I am in the process of developing a unique VeeValidate rule for my VueJS component written in TypeScript. This rule is designed to validate two fields simultaneously, following the guidelines outlined in VeeValidate - Cross Field Validation. Here is a snippet of the code:
<div class="form-group">
<checkbox name="noBarcode" v-model="currentProduct.noBarcode" label=" " />
<i class="info-icon btn-base-element-icon fa fa-info-circle" data-toggle="tooltip" data-placement="left" title="" data-original-title="Tick this checkbox if this product does not have a barcode."></i>
</div>
<div class="form-group">
<text-input v-model="currentProdcut.barcode" label="BarCode" name="barcode" rules="barcode:@noBarcode" />
</div>
Both text-input
and checkbox
are custom form components that utilize ValidationProvider
, based on the instructions provided in Advanced Input Fields.
The custom rule I have created currently appears as follows:
extend('barcode', {
params: ['checkbox'],
validate(value, { checkbox }) {
return checkbox === true || value.length > 0
},
message: "Please enter a barcode. If this product does not have a barcode, tick the checkbox above."
})
However, TypeScript with Vetur is throwing an error message (which seems valid):
Property 'checkbox' does not exist on type 'any[] | Record<string, any>'.
I have been unable to locate any examples of creating custom rules in TypeScript, so I am seeking guidance in that area...