You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've a schema with a type_of_account field and a account_number field. Depending on the type_of_account I've a regex to apply to the account_number field. Reading through this: jaredpalmer/formik#90 and this: #97 I was able to solve it like this:
This works beautifully with the sole problem that, in case of an input error (for example, selecting account_1 and entering only 3 characters) the user will get the generic "Invalid format" error, I'd very much like to display something like "Invalid format, use something like this: 00000000". For that I have the property example in the validations object and tried add the ref to the parameters for displaying on the field, something like:
...
return this.test({
name: "validateAccountNumberFormat",
exclusive: false,
message: msg || "Invalid format, use something like this ${example}",
params: {
example: this.resolve(ref),
},
test: value => value.match(validations[this.resolve(ref)].regex))
});
}
...
Yet, this doesn't work, seems like this promise (ref) isn't available for resolve at this point. So ... how can I do something like this?
Thanks!
The text was updated successfully, but these errors were encountered:
use this.createError()inside your test function, you can pass it params, and it will override/extend the existing ones, but at that point resolve will work.
Hello guys,
I've a schema with a
type_of_account
field and aaccount_number
field. Depending on thetype_of_account
I've a regex to apply to theaccount_number
field. Reading through this: jaredpalmer/formik#90 and this: #97 I was able to solve it like this:This works beautifully with the sole problem that, in case of an input error (for example, selecting account_1 and entering only 3 characters) the user will get the generic "Invalid format" error, I'd very much like to display something like "Invalid format, use something like this: 00000000". For that I have the property
example
in thevalidations
object and tried add the ref to the parameters for displaying on the field, something like:Yet, this doesn't work, seems like this promise (ref) isn't available for resolve at this point. So ... how can I do something like this?
Thanks!
The text was updated successfully, but these errors were encountered: