How can I trigger a customComponent from a form button?

  • Goal: I want to be able to automatically go back to the previous page once a form is submitted.

  • Steps: I was able to create a customComponent button that can go back to the previous page. It uses top level navigation and this Iframe code <script>function goback() {window.history.back()}</script>. I have an event on my form button to try to trigger the custom component but it is not working.
    Screenshot 2023-12-11 at 5.07.44 PM

Navigate back with window.history.back - App Building - Retool Forum

as stated in the link since JavaScript is ran in a sandboxed environment you won't have access to window.history. Jmann does post a comment with a picture/hint as to how you can work around this using a custom component with top level navigation. hope this helps @anon_1 =)

hey thanks for the reply. I got 1 customButton working that is able to go back to the previous page. But I need it to be able to work with the form button, so once a form is validated and the api call is successful then it should automatically go to the previous page. So I am trying to link the buttons together.

I've gotta guess what's going on here so sorry if I'm way off, but I'm guessing you're using 'Validate on Submit' then you have an Event Handler for the Submit event with the action of Control Query to trigger your api call?

Form Submit Button => Validate => Form Submit Event => Trigger Query => Call REST API Resource

if that's right, then I think you should be using the Success Event Handler for the query that calls the API which is the first point in this 'flow' that you would know both if the form was validated and if they api call was successful.

it kinda sounds like you're trying to take the Submit Event from either the Form Button or the Form its self, then control your customButton. This would skip validation and triggering the query which calls the API.