vue-form-generator
vue-form-generator copied to clipboard
validation on checkbox bug - it works only first time
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 }
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 [];
}
}