hx-include or form does not seem to respect validation rules #3175
-
Maybe I'm doing it wrong but neither of these work. https://replit.com/@markgarrigan/hx-include-form This doesn't respect the required attribute and also does not send the form data <div id="content">
<form id="myform">
<input type="text" name="name" required>
</form>
<button form="myform" hx-post="/register" hx-trigger="click once" hx-target="#content">
Submit
</button>
</div> This doesn't respect the required attribute but sends the form data <div id="content">
<form id="myform">
<input type="text" name="name" required>
</form>
<button hx-include="#myform" hx-post="/register" hx-trigger="click once" hx-target="#content">
Submit
</button>
</div> Is this intended, am I doing it wrong, or not intended? Thanks!! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey, First example:
<form id="myform" hx-post="/register.html" hx-target="#content">
<input type="text" name="name" required>
</form>
<button form="myform">
Submit
</button> You will benefit from the default input validation happening as expected, and the form always doing a htmx request as well Second example:
Hope this helps! |
Beta Was this translation helpful? Give feedback.
Hey,
First example:
hx-post
on the form itself anyway, because with that current setup you have, hittingEnter
in the input field will do a standard form submit instead of an htmx-powered one, i.e. here make a full page reload while making aGET
request towards the current page URL, which is likely undesired.You will benefit from the default input validation happening as…