FaridSafi / react-native-gifted-form

📝 « One React-Native form component to rule them all »
MIT License
1.44k stars 214 forks source link

validators don't update if changed because of state change #81

Open faceyspacey opened 7 years ago

faceyspacey commented 7 years ago

If you pass one set of validators on one state, and then call setState and provide a different set, the previous set of validators is what the form is validating against.

faceyspacey commented 7 years ago

Adding the following to GiftedForm.js did the trick:

componentWillReceiveProps(nextProps) {
    GiftedFormManager.stores[nextProps.formName].validators = {};

    if(nextProps.validators !== this.props.validators) {
        for (var key in nextProps.validators) {
          if (nextProps.validators.hasOwnProperty(key)) {
            GiftedFormManager.setValidators(nextProps.formName, key, nextProps.validators[key]);
          }
        }
    }

I'll make a pull request, but perhaps there is a slightly different way you want it done. Let me know.