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
We're using Formily for building forms with the JSON schema approach and we recently implemented a custom E.164 phone number validator method by adding it to the <SchemaField />'s scope and allowing the x-validator to use this method:
telephone: {type: "string",title: "Phone number","x-component": "Telephone","x-component-props": {placeholder: "E.g. 0612345678",},"x-validator": {required: true,triggerType: "onBlur",validator:
"{{(value, rule) => { if (!validatePhone(value)) return rule.message; }}}",// validatePhone is part of our <SchemaField /> 's 'scope'message:
"Check if the phone number entered is correct.",},},
We found out about onBlur, which makes it possible to validate when 'leaving' the field, giving a pretty good user experience: Typing the phone number, move on to the next field, if the phone is correct, no message will be shown, otherwise, message will be shown. Perfect 👍
This onBlur behaviour is something we'd like to have for all fields, by default — but it seems that it is not an option to set the triggerType globally. Means that we have to add { "x-validator": { triggerType: "onBlur", ... } } to the JSON schema for all individual fields. 👎
I used deepwiki to ask if there's some way to support it globally, but it responded that it we would need to build custom logic on onFieldInit, not something we would like as it could break in future.
Is there a way to set this onBlur globally? Or some intention to support this in the future?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
We're using Formily for building forms with the JSON schema approach and we recently implemented a custom E.164 phone number validator method by adding it to the
<SchemaField />
'sscope
and allowing thex-validator
to use this method:We found out about
onBlur
, which makes it possible to validate when 'leaving' the field, giving a pretty good user experience: Typing the phone number, move on to the next field, if the phone is correct, no message will be shown, otherwise, message will be shown. Perfect 👍This
onBlur
behaviour is something we'd like to have for all fields, by default — but it seems that it is not an option to set thetriggerType
globally. Means that we have to add{ "x-validator": { triggerType: "onBlur", ... } }
to the JSON schema for all individual fields. 👎I used deepwiki to ask if there's some way to support it globally, but it responded that it we would need to build custom logic on
onFieldInit
, not something we would like as it could break in future.Is there a way to set this
onBlur
globally? Or some intention to support this in the future?Beta Was this translation helpful? Give feedback.
All reactions