Thursday, 12 February 2015

How to use SPUtility.js file in SharePoint list form for Hide/Show the columns, set a DropDown Changed event and RadioButton changed event using Jquery

How to use SPUtility.js file in SharePoint list form for Hide/Show the columns, set a DropDown Changed event and RadioButton changed event using Jquery:

For this, you should add a content editor webpart inside newform.aspx, where you want to show/hide the list columns. 
Then download the SPUtility.js file from http://sputility.codeplex.com/ and jquery-1.11.2.min.js file as well. we have to add a below script inside content editor WebPart. then it will works.

<script type="text/javascript" src="/Style Library/sputility/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="/Style Library/sputility/sputility.min.js"></script>

<script type="text/javascript">


function OnStatusFieldDropdownChange(spfield) {
    var statusFieldValue = spfield.GetValue(); 
           
    if(statusFieldValue === '4-Closed') {
        SPUtility.GetSPField('Resolved By').Show();
       
        
    } else{ 
        SPUtility.GetSPField('Resolved By').Hide();
        
    }   
}

function OnRadioButtonsChange() {
    var statusFieldValue = SPUtility.GetSPField('Reference Type').GetValue();
    if(statusFieldValue === 'File Attachment') {
        SPUtility.GetSPField('Revision Date').Show();
        SPUtility.GetSPField('URL').Hide();
    } else{
        SPUtility.GetSPField('Revision Date').Hide();
        SPUtility.GetSPField('URL').Show();
    }
}

$(document).ready(function() {


SPUtility.GetSPField('Title').Show();
SPUtility.GetSPField('Resolved By').Hide();
SPUtility.GetSPField("Title").SetValue('Sample Value').MakeReadOnly();

//Set DropDown chnaged event
var statusFieldValue = SPUtility.GetSPField('Status');
 $(statusFieldValue.Dropdown).on('change', function() { 
        OnStatusFieldDropdownChange(statusFieldValue);
    });

//Set Radiobutton changed event
var RreferenceTypeRadio = SPUtility.GetSPField('Reference Type');
$(RreferenceTypeRadio.RadioButtons).each(function(index, obj) {
        var radioButton = obj.value;
        $(radioButton).change(OnRadioButtonsChange);
    });
      
});
</script>

No comments:

Post a Comment