Skip to content
This repository has been archived by the owner on Aug 23, 2022. It is now read-only.

Trigger validations manually #1206

Open
ulisescarreonalvarez opened this issue Oct 1, 2019 · 0 comments
Open

Trigger validations manually #1206

ulisescarreonalvarez opened this issue Oct 1, 2019 · 0 comments

Comments

@ulisescarreonalvarez
Copy link

The Problem

Hi everyone,

We are working with 'react-redux-form', we have our own validations, might be 'fetch' for request info to an API or just simple regex.

Our problem is that we are fetching some languages con the app, so our erros for the validations are on the (state, props) of our component.

We actualy have a validation like this:

   <Field
                  name="email"
                  component={TextFieldRedux}
                  placeholder={(dataLanguagesRegister) ? ((dataLanguagesRegister.hasOwnProperty('4000000005')) ? (dataLanguagesRegister['4000000005'].phraseLocalizedText) : 'Email') : 'Email'} 
                  label={(dataLanguagesRegister) ? ((dataLanguagesRegister.hasOwnProperty('4000000005')) ? (dataLanguagesRegister['4000000005'].phraseLocalizedText) : 'Email') : 'Email'}
                  required
                  validate={[this.requiredEmail, this.validateEmail]}
                  className={classes.field}
                />

and the validation function works like this:

  requiredEmail(value) {
    const { dataLanguagesRegister } = this.state;
    const { languageReducer } = this.props;
    console.log('Required email function', languageReducer);
    if ((languageReducer.dataLanguagesFetched)) {
      if (languageReducer.dataLanguages.hasOwnProperty('4000000034')) {
        return (value == null ? languageReducer.dataLanguages['4000000034'].phraseLocalizedText : undefined);
      }
    }
    return 'Required';
  }

So on the first place we can show the error on English like:
``Email name need to have at least a non free domain.

We have a dispatch for change the language to show something like:

Παρακαλώ εισάγετε μια έγκυρη διεύθυνση ηλεκτρονικού ταχυδρομείου

So, the text on the validation error STILL shows the english phrase, becase the validation need to be triggered on the first place to change and get the new text.

We need a function to trigger all the validations on the language request, thats possible?

Thanks in advance.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant