Is it possible to handle dom event on a form field?

Hello there,
I have an address field on a form. I want to be able to perform an api request when typing value on this field in order to dynamically set other fields like state, zipcode, country, etc.

Is it possible to make that with forestadmin ? Is it possible to handle dom event on form field in forestadmin ?

Thanks!

We got the same use case, and we use ‘onChange’ hook https://docs.forestadmin.com/documentation/reference-guide/actions/create-and-manage-smart-actions/use-a-smart-action-form#change-your-forms-data-based-on-previous-field-values

Our smart action field :

{
  field: 'Adresse complète',
  type: 'String',
  isRequired: true,
  hook: 'onAddressChange'
}

And on the smart action hook section, we perform request and feed, in our case an enum field, with the returned values :

hooks: {
  change: {
    onAddressChange: async ({ fields, changedField }) => {
      if (changedField.value === '') return fields;
      const address = await getAddressSuggestions(changedField.value);
      fields[4].isReadOnly = false;
      fields[4].enums = address;
      return fields;
    },
  },
},
1 Like

Hello @Joel_Alexandre_Khang ,

Indeed as @Justin_Martin said, you can do it using smart actions Use a Smart Action Form - Developer guide :slight_smile:

1 Like

Thank you for your help guys