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

Empty array validation constraint returns undefined error message #90

Open
brauliodiez opened this issue Apr 23, 2019 · 0 comments
Open
Labels

Comments

@brauliodiez
Copy link
Member

brauliodiez commented Apr 23, 2019

Something like:

const hotelFormValidationConstraints: ValidationConstraints = {
  fields: {
    name: [{ validator: Validators.required }],
    city: [],
  }
};

Will produce an undefined FieldValidationResult, e.g.:

        <DropdownForm
          name="city"
          label="city"
          onChange={onFieldUpdate}
          value={hotel.city}
          list={cities}
          error={formErrors.city.errorMessage}
        />

Uncaught (in promise) TypeError: Cannot read property 'errorMessage' of undefined

Workaround:if a given field has no validation check for undefined

  const onFieldUpdate = (id : keyof HotelEntityVm, value : any) => {
    setHotel({
      ...hotel,
      [id]: value
    });

    hotelFormValidation.validateField(hotel, id, value).then(
     (fieldValidationResult) => {
+        if(fieldValidationResult) {
          setHotelFormErrors({
            ...hotelFormErrors,
            [id]: fieldValidationResult
          });  
+        }
      }
    )
@brauliodiez brauliodiez changed the title Empty array validation constraint return undefined error message Empty array validation constraint returns undefined error message Apr 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant