I’m having some trouble with the validation part of useField when utilizing useForm from shopify/react-forms. In a field’s validation, I’d like to refer to a previous fields’ value, and validate on behalf of it’s value.
In the coming example, the second validation function of integerField does not work. I’ve also tried hooking it to a useEffect value containing the same.
const {
fields: {
stringField,
integerField,
},
} = useForm({
fields: {
stringField: useField({
value: data?.stringField || 'specific-string',
validates: [notEmptyString('Please select a price action type')],
}),
integerField: useField({
value: data?.integerField || 10,
validates: [
value => {
if ( value < 0 ) {
return 'Please enter a valid price';
}
},
value => {
if ( data?.stringField === 'another-string' && value < 100 ) {
return 'Please enter a value less than 100';
}
}
],
}),
},
onSubmit,
});
Any ideas?