I want to catch event from setFieldValue()
, with Antd Form.
In this code, if you write on the Input, the functions onFieldsChange
and onValuesChange
will be triggered.
But if you click on the button click me, the function setFieldValue()
is called to update the value of the Input, but the two function are not called.
Thank to anyone can help me.
EDIT
This doesn't seem feasible...
setFieldsValue do not trigger onFieldsChange or onValuesChange?
It's by design. Only user interactive can trigger the change event. This design is aim to avoid call setFieldsValue in change event which may makes loop calling.
It's possible to trigger only
onFieldsChange
event when setting fields to form. Take a look here.You just need to add
rules
to form fields (yes, you will use it to validate form values) then callform.validateFields
right after setting values:The "problem" of this sollution is:
onFieldsChange
will be triggered more than one time wich is not so hard do handle.Also here is a working codesandbox.
Hope this helps:)