Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve get formValidationResult.fieldErrors #84

Open
nasdan opened this issue Apr 21, 2018 · 1 comment
Open

Improve get formValidationResult.fieldErrors #84

nasdan opened this issue Apr 21, 2018 · 1 comment

Comments

@nasdan
Copy link
Member

nasdan commented Apr 21, 2018

When we are going to validate a form and we want to get fieldErrors, i.e in React, we have to :

(formValidationResult) => {
 const dataFormErrors: DataFormErrors = { ...this.state.dataFormErrors };

 formValidationResult.fieldErrors.forEach((fieldValidationResult) => {
   dataFormErrors[fieldValidationResult.key] = fieldValidationResult;
 });

 this.setState({
   ...this.state,
   dataFormErrors,
 });
}

We could create a method helper to encapsulate this mapping, something like :

Pseudocode:

const mapFieldValidationResults = (array: FieldValidationResult[]) => {
   const objectWithFields = { 
    [array[0].key] = array[0], 
    [array[1].key] = array[1],
     ..... 
   }

   return objectWithFields;
}

On future lc-form-validation versions we could return this "objectWithFields" directly on formValidationResult.fieldErrors

@brauliodiez
Copy link
Member

The scenario to cover:

  • User has a form with some validations, these validations errors are not shown because we don't fire them til the user interacts with the inputs (touched).

  • If the user click on the submit option, the validation form will be fired, but the error messages per field won't be updated.

We need an easy way to fullfill them.

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

No branches or pull requests

2 participants