Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing custom input data properties into :validation-rules params #459

Closed
BennaceurHichem opened this issue Jul 3, 2021 · 1 comment
Closed

Comments

@BennaceurHichem
Copy link

Discussed in https://github.com/wearebraid/vue-formulate/discussions/458

Originally posted by BennaceurHichem July 3, 2021
I'm implementing a phoneInput that contain two parts, the first is the flag of the country, with the countryCode and dialCode, the second is the phone input, I want to create a custom validation that validates the phone number using an external library which libphonenumber-js.
Th problem is that in the params passed into :validation-rules is the value only as I see in the doc : https://vueformulate.com/guide/validation/#custom-validation-rules

How can I pass the countryCode which is a data property in the custol input, to the params of the :validation-rules prop, to use it for validation with libphonenumber-js like this :

 :validation-rules="{
        phoneValidation: ({ value,//here I shoul get the countryCode }) => {
          const pn = parsePhoneNumberFromString(value, //passcountryCode here for custom validation);
          return pn?.isValid() ? true : false;
        },
      }"
```</div>
@justin-schroeder
Copy link
Member

@BennaceurHichem there are 2 arguments, for example:

<FormulateInput
  validation="phoneValidation:+1,usa"
/>
phoneValidation: ({ value }, countryCode, countryName) {
 // do your validation here 🎉
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants