Skip to content

Commit

Permalink
Merge pull request #76 from legalthings/group-validation
Browse files Browse the repository at this point in the history
validation: add custom validation for group checkboxes
  • Loading branch information
svenstm authored Oct 30, 2017
2 parents a5ed2ae + d41241f commit f528521
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions js/legalform-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,29 @@
return;
}

// Implement validation for group checkboxes
if (meta.type === 'group') {
const checkBoxId = $(input).attr('data-id');
const allCheckboxes = $("[data-id='" + checkBoxId + "']");
const isRequired = !$(input).closest('.form-group').find('label > span').length ? false :
$(input).closest('.form-group').find('label > span')[0].className === 'required' ? true : false;

let checked = 0;

for (var i = 0; i < allCheckboxes.length; i++) {
if (allCheckboxes[i].checked) {
checked++;
} else {
$(allCheckboxes[i]).prop('required', false);
}
}

if (isRequired && checked === 0) {
$(input).get(0).setCustomValidity(error);
return;
}
}

// Implement validation for numbers
if (meta.type === 'number') {
var min = $(input).attr('min');
Expand Down

0 comments on commit f528521

Please sign in to comment.