Passing argument to the Field validation?
See original GitHub issueI am wondering if you could pass arguments to the Field level validation like so:
<Field name="username" type="text"
component={renderField} label="Username"
validate={[ required('an argument to this function'), maxLength15 ]}
/>
// The validator
const required = (value, message = 'This is required') => value ? undefined : message;
This would make it easy to customize messages based on the field, without needing to create a validation function which will repeat a lot of code just to have a suiting message.
Issue Analytics
- State:
- Created 7 years ago
- Comments:18 (1 by maintainers)
Top Results From Across the Web
django - Passing an argument from views to Form Validation
Is there a way I can get the product gotten from product = Product.objects.get(id=id) and use it in my form validation?
Read more >passing arguments to the validation - WordPress.org
I just need to pass the post_id using a form argument. I defined the form argument while loading the form add_filter('acfe/form/load/form=prop_edit', ' ...
Read more >How to pass parameters to a custom validator in Sitecore
I have a custom validator class, to validate a General Link field. It checks that the field value of the Description field is...
Read more >Function Argument Validation - MATLAB & Simulink
Function argument validation is a way to declare specific restrictions on function arguments. Using argument validation you can constrain the class, size, and ......
Read more >How to Pass Argument to the Required Field Validator
So pls provide me the solution how can i pass the parameter of id to required field validator. Thanks. Posted 9-Sep-13 0:27am.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
⚠️ WARNING ⚠️
Beware of doing this:
As tempting and elegant as it looks, this will construct a new function every time your form is rendered, which will cause your field to rerender (because
this.props.validate !== nextProps.validate
).This is why I specifically defined a single instance of my parameterized validation rules in the example:
I’ve found the solution for this…
The above implementation shows me the error msg properly for the respective field.
@erikras : Please let me know your thoughts on this.