When it first makes them unrequired it seems to work as expected. However if I make them required then switch back to unrequired then the 'Other' selection is saying it's required from then on out. So it expects the "Other" field to always be checked. The "dayList<Input/Span>" variables are for the checkbox field. The "date<Input/Span>" variables are for a date field and that one is working just fine.
Note: The hide and show of the span is working as it should.
function setRequired(dayText, isRequired) { /* find the fields that the required attribute is to be modified */ /* Each field's input and the span */ /* the span holds the astrix that is displayed when required */ var dayListSpan = $('.day' + dayText + 'Symptoms span.cf-required'); var dayListInput = $('.day' + dayText + 'Symptoms input'); var dateSpan = $('.day' + dayText + 'Date span.cf-required'); var dateInput = $('.day' + dayText + 'Date input'); var dayEnteredByInput = $('.day' + dayText + 'EnteredBy input'); if (isRequired) { dayListSpan.show(); dayListInput.attr('required', 'True'); dateSpan.show(); dateInput.attr('required', 'True'); /* set the Entered by value to the current user */ dayEnteredByInput.val(currUser).change(); } else { dayListSpan.hide(); dayListInput.removeClass('required').removeAttr('required'); dateSpan.hide(); dateInput.removeClass('required').removeAttr('required'); /* clear the Entered by value */ dayEnteredByInput.val('').change(); }; };
Note: the reason for passing it "dayText" is that I have several tabs with the same data being entered and only the slight name change, so I'm passing in the different part of the name and using that to get the exact fields. The Users did not want to use a collection.