Skip to content

Commit

Permalink
Make checkbox valid when at least one checkbox is checked (#490)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinchappell authored May 24, 2017
1 parent a5ae640 commit 4fa1233
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion demo/assets/js/form-builder.min.js

Large diffs are not rendered by default.

Binary file modified demo/assets/js/form-builder.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion demo/assets/js/form-render.min.js

Large diffs are not rendered by default.

Binary file modified demo/assets/js/form-render.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/form-builder.min.js

Large diffs are not rendered by default.

Binary file modified dist/form-builder.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/form-render.min.js

Large diffs are not rendered by default.

Binary file modified dist/form-render.min.js.gz
Binary file not shown.
17 changes: 10 additions & 7 deletions src/js/control/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ export default class controlSelect extends control {
*/
groupRequired() {
const checkboxes = this.element.getElementsByTagName('input');
let minReq = control.mi18n('minSelectionRequired', 1);
const setValidity = (checkbox, isValid) => {
if (!isValid) {
let minReq = control.mi18n('minSelectionRequired', 1);
checkbox.setCustomValidity(minReq);
} else {
checkbox.setCustomValidity('');
Expand All @@ -168,12 +168,15 @@ export default class controlSelect extends control {
});
};

this.element.addEventListener('click', evt => {
if (evt.target.type === 'checkbox') {
let isValid = [].some.call(checkboxes, cb => cb.checked);
toggleRequired(checkboxes, isValid);
}
});
const toggleValid = () => {
let isValid = [].some.call(checkboxes, cb => cb.checked);
toggleRequired(checkboxes, isValid);
};

for (let i = checkboxes.length - 1; i >= 0; i--) {
checkboxes[i].addEventListener('change', toggleValid);
}
toggleValid();
}

/**
Expand Down

0 comments on commit 4fa1233

Please sign in to comment.