revalidate icon indicating copy to clipboard operation
revalidate copied to clipboard

Accessing other fields in array structure

Open shunxing opened this issue 6 years ago • 0 comments

Hi I'm trying to create a validator on an array of passenger (object structure). In each passenger, I have his firstName and lastName.

I have to trigger firstName and lastName error when we have the same passenger name (first name + last name).

I'd like to know if we can easily access the firstName in the lastName composeValidator and also in the other way back (accessing to the field lastName in the firstName composeValidator)

Is it a great way to do so ?

"passengers[]": {
	name: createValidator(
		() => passengerName => {
			return {
				lastName: lastNameValidator(passengerName.firstName),
				firstName: firstNameValidator(passengerName.lastName),
				gender: isRequired({
					message: validationMessages.genderRequired,
				}),
			};
		},
		message
	)(message),

shunxing avatar Feb 07 '19 11:02 shunxing