question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Passing additional data into <Field /> which will be accessible in validate

See original GitHub issue

I need to pass additional object myCustomData which I can access in meta.data <Field name="firstName" myCustomData={{isOk: true}} validate={(value, values, meta) =>{ return meta.data.myCustomData.isOk ? null : 'Error' }} />

Passing additional data into Field which I can access in 'validate ’ function would be very helpful

_Originally posted by @lock in https://github.com/final-form/react-final-form/issues/355#issuecomment-544117342_

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

3reactions
jsrhodes15commented, Dec 11, 2019

Just an avid consumer of this library, so author/maintainers feel free to correct me, but my advice would be to use a curried function here. We do this all the time:

const customIsValid = (data) => (value) => data.isOk ? undefined : 'Error';

<Field 
  name="too"
  validate={customIsValid({isOk: true})
 >

With this pattern you have/can have access to whatever values you need.

1reaction
msagerydcommented, Dec 12, 2019

@marrkeri You didn’t write that you wanted to update the data, so I didn’t answer that question. The code I wrote above is just the initialisation part. If you want to update meta.data you can do this with a mutator. Or even install one of Erik’s companion libs for this (it’s actually just one function). https://www.npmjs.com/package/final-form-set-field-data

One of Erik’s blog posts describes this. The second part (about field warnings) might apply to your use case: https://blog.cloudboost.io/final-form-decorators-calculated-fields-and-warnings-bf9cccd21b7e

Read more comments on GitHub >

github_iconTop Results From Across the Web

Restrict data input by using validation rules - Microsoft Support
Validations rules help you check data as it is added to your Access desktop database which improves accuracy and consistency of data entry....
Read more >
Validating Input | Web Accessibility Initiative (WAI) - W3C
Validation should aim to be as accommodating as possible of different forms of input for particular data types. For example, telephone numbers are...
Read more >
Data Validation – How to Check User Input on HTML Forms ...
We need form validation anytime we are accepting user input. We must ensure that the data entered is in the correct format, lies...
Read more >
Client-side form validation - Learn web development | MDN
Go to any popular site with a registration form, and you will notice that they provide feedback when you don't enter your data...
Read more >
Validation - Laravel - The PHP Framework For Web Artisans
As you can see, the validation rules are passed into the validate method. Don't worry - all available validation rules are documented. Again,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found