Skip to content

Instantly share code, notes, and snippets.

@Alireza2n
Last active February 8, 2018 16:18
Show Gist options
  • Save Alireza2n/cb263722adaf64261482b62c2d1b7960 to your computer and use it in GitHub Desktop.
Save Alireza2n/cb263722adaf64261482b62c2d1b7960 to your computer and use it in GitHub Desktop.
dynamically add and remove required based on radio select using jqueryvalidation library
$(document).ready(function () {
$("#approval_form").validate();
$('input[type=radio][name=status]').on('change', function () {
switch ($(this).val()) {
case '1':
console.log('case 1');
$("#id_notes").rules('remove', 'required');
break;
case '0':
console.log('case 0');
$("#id_notes").rules('add', {
required: true
});
break;
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment