Form submit type button fails to use latest form.data in query

Hi, I've spent the last hour or so trying to understand some form and query behaviour but have run out of ideas. Would be great to know if this is a bug or a lack of understanding on my part!

Aim: Use a form to trigger a JS script which triggers a postgres query to update a database record.

Issue: Using the form submit type button results in the query ignoring the latest form.data

Workaround: Change the form button type from submit to default.

Question: Why doesn't the submit type work? Inspecting form.data shows it has the latest field values, so why isn't it used in the query?

Screenshots attached showing the failing and working setup.



Does the form always have an ID? The JS Query is looking for the id and if no id then add new client - are you always updating or adding?
What does the form data look like?

Hey @ScottR The form is passed an ID when the aim is to update, and no id is passed when creating a new client. You can see the form.data in the bottom left of the screengrabs in the state inspector. The form.data always appears correct in the inspector, it just seems stale data is used by the submit type button

Aah I just found the cause, I had 'Reset after successful submit' enabled on the form, so immediately after hitting submit the form fields were reverting back to their original value, and these were then being used in the update query. Disabling this option means it works as expected.

1 Like