I have radio buttons and checkboxes that I have disabled in my Javascript to prevent additional user interaction. In order for the values to be saved however, I have to enable them again prior to submit. I do it with code like this:
$('.action-btn.Submit').on('click', function() { $('.disabled').each(function() { $(this).removeAttr('disabled'); $(this).removeClass('disabled'); }); }); //end of $(".action-btn.Submit").on('click', function() {
This works, other than when a submit is attempted with missing required fields. The submit will fail, and prompt the user to correct the fields, but now the radio buttons and checkboxes have been enabled. I want to avoid this.
I've done other actions before with text fields, checking for the value of all required text fields and only performing the action if they are not blank, and that works well for text fields, but not for radio buttons and checkboxes since their values are a more complex proposition.
Is there a clean way to either:
1. Check that all required fields are complete before processing the action to enable the radio buttons and checkboxes, or
2. If the submit fails, trigger some code to disable the fields again?
Thanks!