PricingDocsAcademy
Bluesky ...
Wed, Dec 11, 9:47 PM

What is the correct way to submit a form in toddle?

  • /attachments/1307010177022689361/1307010177337135104/image.png

    Sean

    26 days ago

    My initial understanding was that the correct way to submit a form in toddle is to set a submit event on the form element and then add a type=submit attribute to the button element inside the form that would trigger the form submission. Then I put my API call or any logic into the form's submit event actions. But while troubleshooting a form that wasn't submitting, I asked the toddle AI and I got this (see screenshot).

    Does this mean that the correct way to set up the form in toddle is to
    1) Not set any event on the form element
    2) Set a type=button attribute on the submit button.
    3) Set the submission logic or API call to this submit button's click event?
    image.png
  • Lucas G

    26 days ago

    No, I think the answer it is giving you is out of context
  • If I remember correctly, there was a user that wanted to trigger different things from inside a form without submitting it.
  • In such a case, the button shouldn’t be type submit
  • Your current method is the proper way to submit a form
  • Lucas G

    26 days ago

    That is, if you want to take advantage of browser validation and stuff like that
    🙌1
  • Tom Ireland

    26 days ago

    This ☝️
  • Sean

    26 days ago

    Thanks Lucas.
  • Sean

    26 days ago

    Sorry one last thing. My form doesn't have a "button" element per se, it has an instance of a button component that I've created (ui-button). Now in my ui-button component (master), I started with the button tags and set up my button with icons left and right and all of that. I also added a type attribute that takes a value from the outside (button instance) and sets the type attribute of the actual button component to submit. For some reason this does NOT trigger the form when I click it. If however, instead of using a button component, I use a regular button element inside my form and set its type to submit, then that triggers the form submission. Looks like there's something off with my button component and that it's not taking the submit attribute from the instance or something. Am I approaching this the right way? What else could I be overlooking?
  • Lucas G

    26 days ago

    What do you mean by outside the button instance?
  • Basically you’re seeing the type attribute in the button via a component attribute
  • Is that right?
  • Sean

    26 days ago

    The submitting element is not a button element itself, it is an instance of a custom button component and I added a type attribute to this component. Now in the instance, that is, the actual element in the form, I set this type attribute to submit. Then on the component, not the instance, I catch this attribute (fed in by the instance), and set the top layer to have a type attribute = attribute passed into the component, which is "submit". Could it be that the reason this isn't working for me is because I'm using a custom component (ui-button) to trigger the form's submit event? Because instead of a component, if I use a native button element in the form (no component), then the form submits fine.
  • Lucas G

    26 days ago

    No it shouldn’t be an issue
  • I use button components as well
  • Sean

    26 days ago

    Hmm..
  • Lucas G

    26 days ago

    You can send a link if you’d like
  • Lucas G

    26 days ago

    You have a Prevent Default on your button's click
  • That will break the click
  • It works without it
  • 😂1
    ❤️1

Stop scrolling. Start building.

toddle is a visual web app builder that rivals custom code — but accessible to your entire team!

Try toddle — it's free!

© Copyright 2024 toddle. All rights reserved.