Clear a modal Form on cancel or close selection

HI

I am trying to work out how to clear a from in a Modal if the user clicks a “Cancel” button (which closes the modal) or the Close icon X.

I thought it might be as simple as having an onclick event to reset the form but it doesn’t seem to work. I assume it is closing the modal before it has time to clear the forms contents?

Can anyone throw me in the right direction?

Cheers!

You can use a dynamic event for ‘hide’ or ‘hidden’ on the modal to clear a form, run a flow, change a value etc.


You could flip it around and have the form reset on modal ‘show’

1 Like

Yep, I use the ‘Hide’ event on all my modals to reset the forms in them when they’re closed and it works like a charm.

3 Likes

Same. Very useful!

1 Like

Thanks everyone, this will come in handy!

1 Like

I am assuming that you are talking about an insert form where the form starts out with blank fields.

When it comes to an update form then I have issues. On opening the modal form, the fields are populated with data from the record that you want to update. Make a change, submit and close the modal, or cancel and close the modal. Move on to a second record and open the modal, then I see the data from the first record, only for an instant, before the fields are populated with the data from the second record.

Does anyone else have this?

When I go to that second record I would rather the fields appeared blank at first, or really they should just be populated with the correct data from the second record.

That is a totally different question.

You can't do that, it's an update record form showing the data from the database it cannot be blank.

so how is this set up - set record/show modal? How is this done on the page?

Hi Neil,
You can perform a form reset using the modal hide dynamic event. Select the modal, click dynamic events and you should see options for the modal. That way, when the modal is closed, following the first update, the form is reset. When the modal is then shown for the next record, it will have been reset and will be populated when the SC completes.

An alternative approach I have used, which has been quite good is to add a variable in the modal for the id of the record I am updating - initialise with a value of 0. When I click on a button (or other element) to trigger the update, rather than triggering the SC straight away, I update the variable with the ID.

The variable has an onupdated event to trigger the SC call passing the value as a parameter (use an inline flow with a condition that value != 0 otherwise it will trigger every time the page is loaded/modal closed). The SC that fetches the details to be updated has an onsuccess event that opens the modal. This way the modal only opens once the data is available. The final part is to reset the form and set the variable back to 0 on modal hide.

It takes a bit more time to set up this way but, in my opinion, it looks better than having the flicker of blank to populated that you get by opening the modal before the data is ready.