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.

Dynamically changed validation prop

See original GitHub issue

Are you submitting a bug report or a feature request?

Bug?

What is the current behavior?

If you dynamically change validation prop or render Field without validation prop with name of the field that had this prop before, the validation still remains.

{
    	check === 'yes' ?
          <Field name='lastName' type='text' 
          component={renderField}
          validate={[required]}/> :
              <div><Field name='lastName' type='text' 
          component={renderField} />No validation</div>
    }

https://jsfiddle.net/e8osasy2/4/ In the example:

  1. Touch “Last” field (validation error will appear)
  2. Change “yes” to any other value

What is the expected behavior?

validation error should go away as soon as validation prop is changed

What’s your environment?

6.5.0

Other informations

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
mqklincommented, Feb 19, 2017

I guess you shouldn’t change validate prop.

Instead you can move validate logic into validate function itself:

const required = (value, allValues) => {
  if (allValues.check !== 'yes') return undefined;
  return value === 'hello' ? undefined : 'Must be polite'; 
}

https://jsfiddle.net/e8osasy2/6/

http://redux-form.com/6.5.0/docs/api/Field.md/#-validate-value-allvalues-props-error-optional-

1reaction
danielrobcommented, Jul 24, 2017

@alvelig Thanks for your clear communication throughout this thread. We’ve recently had a change which you can see here: #3094 and read about here: #3211. I suspect this may have fixed or changed the nature of this issue.

Would you be willing to verify on a recent version of redux-form after that change?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Validate props with PropTypes if it have dynamic name
In my react app I have component, in which i pass props. Props can have different names. I want validate them with PropTypes...
Read more >
How to dynamically/conditionally change the Required ...
I have not yet discovered how to access the fields' Required property after the form is rendered, or how to inform the validation...
Read more >
Dynamic field validation in Reactjs | by Unisha Acharya
In this article, we will be validating the dynamic fields. ... Dynamic field validation in Reactjs ... onChange={(e) => props.change(e)}
Read more >
Form - Dynamic change required field validation
Disclaimer: The information provided on DevExpress.com and its affiliated web properties is provided "as is" without warranty of any kind.
Read more >
How to Add Form Validation to React Dynamic Forms
Formik and Yup can help to create form validation in React. ... In config.json , change the existing code to: { "development": {...
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