can the Form execute different validator by different trigger?
See original GitHub issue- I have searched the issues of this repository and believe that this is not a duplicate.
What problem does this feature solve?
eg: There is an input-component, which need to validate the format and calculate the value. such as ID Card No input-component. I want to validate the format while inputting and to calculate the value while being finished. I wish when the inputting doesn’t finish, it can’t return an error. Because if return an error, it isn’t friendly. But when the on-blur happened, it can return an error “Please input the correct format!”
codepen: https://codepen.io/panjunfen/pen/VNrLpr?editors=0010
What does the proposed API look like?
in the rule object, add a key “trigger”.
such as,
[{
pattern: /^([A-Z]{0,2}|[A-Z]{1,2}\d{0,6}|[A-Z]{1,2}\d{6}([0-9A]{0,1}){0,1})$/,
trigger: ‘onChange’,
},{
validator: (rule, value, callback)=>{
console.log(validator value:${value} rule:
,rule);
if(!value || value.search(/^[A-Z]{1,2}\d{6}([0-9A])$/) == -1){
callback();
return ;
}
if(validHKID(value)){
callback();
} else {
callback(“The ID is incorrect!”);
}
},
trigger: ‘onChange’
},{
pattern: /^[A-Z]{1,2}\d{6}([0-9A])$/,
trigger: ‘onBlur’
}]
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (5 by maintainers)
https://codesandbox.io/s/jibenshiyong-antd4150-forked-k7rfu?file=/index.js
antd v4 enabled rules with different
triggerValidator
. Seems this issue can be closed now.just clarifying that @zombieJ meant
validateTrigger