Updating checkbox in a checkbox group doesn't work

  • 4 August 2015
  • 1 reply
  • 2 views

Badge +1

So here's what I'm trying to do - the edit form is launched after uploading a document. The user then gets to select a library from a drop down list. After clicking a "Refresh" button, I pull back all documents in that library based on certain criteria and fills a drop down list with all the document titles. The user then selects a title from the list and the document's metadata is then pulled from the library and filled into the current form.

 

I have a clearFields function which just clears all the current form's fields back to an empty state. This is so if the user selects the wrong document title and selects another, it'll only have the proper metadata fields. In this function, I have a loop that goes thru a checkbox group and sets everything to false so they won't be checked.

 

The problem - after the loop marks all the checkboxes' value to false, when I try to go thru the checkbox group again to mark certain items as true (based on metadata of the selected document), the checkboxes will never get updated to be marked as checked. If I remove the portion of the code where I switch the attribute checked to false, it works no problem. But then I have the possibility of having invalid fields checked because of previous metadata selected.


1 reply

Badge +1

After further testing and research, found out not to use .attr but use .prop instead. For some reason, .attr will not allow you to remark the checkbox as true after marking it as false but .prop works.

NWF$("#" + checkboxName).find("input[value='Checkbox Value').prop("checked", true);

Reply