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
});
+ }
}
)
Something like:
Will produce an undefined FieldValidationResult, e.g.:
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 }); + } } )