TanStackT
TanStack5w ago
17 replies
hurt-tomato

listeners.onChange not fired when calling form.setFieldValue

Hey, I have the following issue. I want to update the form field value by calling setFieldValue from the useForm result. But when I am calling it's my listeners.onChange from useForm is not called.

return useForm({
  defaultValues: initialJob,
  listeners: {
    onChangeDebounceMs: 500,
    onChange: ({ formApi, fieldApi }) => {
      if (formApi.state.isValid) {
        updateFieldKeysRef.current = R.uniq(
          R.concat(updateFieldKeysRef.current, [fieldApi.name]),
        );
        formApi.handleSubmit();
      }
    },
  },
})


I am passing these useForm values in a context then, when some of my custom component fields change, I am doing:

const {form} = useEditorContext();
const handleUpdateSkill = (type: SkillType) => (name: string, level: number) => {
  ...
  form.setFieldValue("skills", newSkills);
};


Is it by demand, or is it a bug?
Was this page helpful?