Open ahmed-shahrour opened 5 years ago
Hi, To validate only one field you can use validate method declared in abstractField mixin. You can find it here (https://github.com/vue-generators/vue-form-generator/blob/master/src/fields/abstractField.js)
Example:
<script>
export default {
name: 'DatePickerField',
mixins: [abstractField],
methods: {
handleDateChange() {
[...do your stuff]
this.validate(); // This method triggers this field validation only
}
}
}
</script>
I had the same issue with 2 separate checkboxes for which it was not allowed to be both checked. I had to implement the quickfix from @ahmadshahrour951.
It would be nice if we could reach other fields from the validator or custom field to manually call validate
on a different field.
I'm submitting a ...
What is the current behavior?
Currently, I have two input date fields in my form along with another few. One is
startDate
and the other isendDate
. LogicallystartDate
must be beforeendDate
, andendDate
must be afterstartDate
.These are the custom validators I created for each:
startDate
:endDate
:They are both dependants on each other and I cannot force validate one field without validating the other.
Example: I set (mistakingly)
startDate
to be: "2019-07-01" then I setendDate
to be: "2019-06-01"If I set
options: { validateAfterChanged: true }
, then I get a validation red box css happening on the endDate once I selected the date. Now I noticed my mistake I will setstartDate
to be: "2019-05-01".endDate
will continue to be invalid css.The only clean way I figured out to solve the issue is to attach
@model-updated="onModelUpdated"
andref="vfg"
to the<VueFormGenerator />
component, then for every change in the model, I force validate the whole form usingthis.$refs.vfg.validate()
in theonModelUpdated
method. If there are other fields in the form, then they will be validated as well for any change instartDate
orendDate
, which I don't want.Suggestion Would it be possible to have a
.validate()
method for a specific field?Please tell us about your environment: