Skip to content
Advertisement

How do I access another field using vuelidate

I’m making some validators on a form for shipping using vuelidate. Currently I’m checcking if the postalCode is in the right format. This field is dependent on the country field though (because different countries have different postal code formats. I’m having trouble accessing the viewmodel itself though, and I don’t get the explanation in vuelidates docs.

Currently I’m working with the following redacted code:

JavaScript

for completeness, a snippet of the form:

JavaScript

Advertisement

Answer

this context may be in use in some cases (not in this one). but it obviously isn’t available as component instance inside arrow function.

As the documentation shows, component instance is available in custom validator as the second parameter:

JavaScript

This applies to Vuelidate 0.x and doesn’t work the same way with 2.x and composition API.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement