Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
74
rated 0 times [  81] [ 7]  / answers: 1 / hits: 19377  / 5 Years ago, mon, august 19, 2019, 12:00:00

In ant design one can provide a custom validator like the following:



<Form.Item label=First Name>
{getFieldDecorator(firstName, {
rules: [
{
validator: (rule: any, value: string, cb: (msg?: string) => void) => {
value.length < 3 ? cb(too short) : cb();
}
}
]
})(<Input />)}
</Form.Item>


As you see I'm using typescript and cause its transpiler is really cool it wants me to use rule parameter of validator as well. I can't find any documentation on it and don't know what is good for. So if you can please explain briefly what is it and how it should be used?


More From » typescript

 Answers
624

As part of Validation Rules validator accepts rules as first argument.


Due to the fact it's a wrapper for async-validator, you can check the Rules specification:



function(rule, value, callback, source, options)


rule: The validation rule in the source descriptor that corresponds to the field name being validated. It is always assigned a field property with the name of the field being validated.



You also can put a breakpoint and see its value for your needs.


[#51752] Monday, August 12, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
heidys

Total Points: 665
Total Questions: 102
Total Answers: 97

Location: Belarus
Member since Sat, Jul 18, 2020
4 Years ago
;