Skip to content

Improve get formValidationResult.fieldErrors #84

Open

Description

@nasdan

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

Activity

  1. brauliodiez commented on Apr 21, 2018

    @brauliodiez
    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions