TanStackT
TanStack12mo ago
7 replies
exclusive-coral

how to disable field based async validation if value === defaultValue

hi, i try to disable async validation (ask the server if the value exists) if the current value is the defaultValue of this field. i want to use:

//...
onChangeAsync: ({value, fieldApi}) => {
  if(value === fieldApi.form.options.defaultValues[fieldApi.name]) {
    return undefined; 
    // (or null or true, i actuallay dont know what the yup adapter needs)
  }
  return anyYupSchema;
}
//...


but i got everytime "Invalid Form Values" and validation does not work. i think the return for the validation adapter should be different.

i tried also with updating the field options at form level with fieldApi.update(updatedOptions) but i think there is maybe a bug‽ after updating the field options, the meta field errors is undefined or null (cant remember) instead of an empty array like after initialisation.
Was this page helpful?