fixed checkboxes still validating while having no value and marked as optional

This commit is contained in:
2025-04-07 10:58:27 -04:00
parent 80e996a281
commit b232313c59
2 changed files with 2 additions and 2 deletions

View File

@ -58,7 +58,7 @@
<fieldset class="form-group"> <fieldset class="form-group">
<legend>Check Group</legend> <legend>Check Group</legend>
<span class="form-group__item"> <span class="form-group__item">
<input data-validation='{"maxCount": 2}' id="checkbox-1" type="checkbox" name="checks"> <input id="checkbox-1" type="checkbox" name="checks">
<label for="checkbox-1">Checkbox 1</label> <label for="checkbox-1">Checkbox 1</label>
</span> </span>
<span class="form-group__item"> <span class="form-group__item">

View File

@ -277,7 +277,7 @@ class Validation {
const nameAttrVal = fieldInstance.el.name const nameAttrVal = fieldInstance.el.name
if (!fieldInstance.optional && this.validateForBlank(fieldInstance) || if (!fieldInstance.optional && this.validateForBlank(fieldInstance) ||
(fieldInstance.optional && fieldInstance.el.value !== '')) { (fieldInstance.optional && (fieldInstance.el.value !== '' && fieldInstance.el.checked))) {
switch (fieldInstance.el.type) { switch (fieldInstance.el.type) {
case 'checkbox': case 'checkbox':
this.validateCheckbox(fieldInstance, nameAttrVal) this.validateCheckbox(fieldInstance, nameAttrVal)