Skip to content

Empty array validation constraint returns undefined error message #90

Description

@brauliodiez

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
          });  
+        }
      }
    )

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions