vue-form-generator icon indicating copy to clipboard operation
vue-form-generator copied to clipboard

validation on checkbox bug - it works only first time

Open nattyluke opened this issue 6 years ago • 1 comments

I have a required input text and a required checkbox. If i test the formular it works, 2 errors showing up. if i check the checkbox, validate again, then uncheck the checkbox, and write in the required text field, the validator doesnt see that the checkbox is unchecked. My code: { type: "checkbox", model: this.name, label: this.label, required: this.required, validator: validator.required, default: false }

nattyluke avatar Nov 08 '19 15:11 nattyluke

I have had this happening to me because required setting only checks for an empty value, and in the code false doesn't count as an empty value, how I solved this was using a custom validator:

function(value){
      if(value == false){
           return ["This value must be checked"];
       } else{
           return [];
      }
}

elabx avatar Jun 22 '20 17:06 elabx