I want to create custom rules for a form.
The example would be this:
<label class="form-label">Price range from</label>
<validation-provider rules="required_if:price_to" name="Price range from"
v-slot="{ errors }">
<input v-model="price_range_from" type="number"
ref="price_from">
<span class="validation-error form-span">{{ errors[0] }}</span>
</validation-provider>
</div>
<div class="ml-2 w-100">
<label class="form-label">Price range to</label>
<validation-provider name="Price range to"
v-slot="{ errors }">
<input v-model="price_range_to" type="number" class="form-control"
ref="price_to" name="price_range_to">
<span class="validation-error form-span">{{ errors[0] }}</span>
</validation-provider>
Out of this part of form I want to create a rule which has logic of this:
inputofprice_range_fromisrequiredif theprice_range_tofield is notnull.inputofprice_range_fromcannot be greater thenprice_range_to.- And vice versa.
Script:
import {ValidationProvider, ValidationObserver, extend} from 'vee-validate';
import * as rules from "vee-validate/dist/rules";
import {required} from 'vee-validate/dist/rules';
Object.keys(rules).forEach(rule => {
extend(rule, rules[rule]);
});
extend('required', {
...required,
message: 'This field is required'
});
Tried to read the documentation on [https://logaretm.github.io/vee-validate/guide/forms.html] But couldn't find the answer how to make custom rules.
Would be glad if someone showed and example that I could understand and move forward and make more custom rules.