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

  • burner918-1307010177022689361

    Sean

    4 months 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?
    1307010177337135104-image.png
  • lucasg-1307010728213090355

    Lucas G

    4 months 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
  • lucasg-1307011508596772866

    Lucas G

    4 months ago

    That is, if you want to take advantage of browser validation and stuff like that
    🙌1
  • tomthebigtree-1307018697084506113

    Tom Ireland

    4 months ago

    This ☝️
  • burner918-1307021075003215883

    Sean

    4 months ago

    Thanks Lucas.
  • burner918-1307026704165765231

    Sean

    4 months 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?
  • lucasg-1307027633879388205

    Lucas G

    4 months 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?
  • burner918-1307029769824505928

    Sean

    4 months 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.
  • lucasg-1307030523587199007

    Lucas G

    4 months ago

    No it shouldn’t be an issue
  • I use button components as well
  • burner918-1307031298845704344

    Sean

    4 months ago

    Hmm..
  • lucasg-1307031720104558647

    Lucas G

    4 months ago

    You can send a link if you’d like
  • lucasg-1307047691145969745

    Lucas G

    4 months ago

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

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.