This project has moved and is read-only. For the latest updates, please go here.
1
Vote

Setting multi-value field based on dropdown, then clear when dropdown changes.

description

So I have a newform.aspx unedited file that I am using SPUtility to hide fields with. I have a dropdown that when an option is selected 2-3 other fields are shown and the rest hidden.

All works fine with that, I can change options and it will hide other fields and show the right fields. The other step to this is the need to check a multi-selectable checkbox area based on the dropdown choice. I was able to set the value, but the issue is when I change the dropdown, the value is not cleared. I didn't find in the documentation, and I could have overlooked it, how to clear the value. Here is some code of what I am doing. I've got a couple rows of else ifs in there as well, but its just more of the first if with different Show/Hide Values for the drop-down field. Fairly new to jquery/js so I could also be missing some basic functionality here.
    var AOField = SPUtility.GetSPField('Additional Options');
    // show or hide uneccesary dropdown values
                var showOrHideField = function() {
                    var PGFieldValue = PGField.GetValue();
                    // Hide the fields based on Practice Area
                    if(PGFieldValue === 'Litigation - Attorney') {
                        SPUtility.ShowSPField('States Licensed');
                        SPUtility.ShowSPField('Litigation Focus Area');
                        SPUtility.ShowSPField('Attorney Title');
                        SPUtility.HideSPField('Reg-Bus Focus Area');
                        SPUtility.HideSPField('Reg-Bus Staff Title');
                        SPUtility.HideSPField('Support Staff Job Title');
                        SPUtility.HideSPField('Litigation Staff Title');
                        AOField.SetValue('Letterhead');
                        AOField.SetValue('Citrix');
                        AOField.SetValue('Fax');
                        AOField.SetValue('Good');
                    }

comments

jamescoffman wrote Aug 23, 2016 at 9:09 PM

Ok so after running around the jquery website I found that when I wanted to deselect all checkboxes I could use the prop function so this is what I put in one of my else if statements:
$(':checkbox').prop('checked', false);