Skip to content

hx-include or form does not seem to respect validation rules #3175

Answered by Telroshan
markgarrigan asked this question in Q&A
Discussion options

You must be logged in to vote

Hey,

First example:

  • You likely want to put the hx-post on the form itself anyway, because with that current setup you have, hitting Enter 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 a GET request towards the current page URL, which is likely undesired.
  • If you try hitting Enter in the empty input, you'll notice the default validation triggers as well
  • If you instead do the following:
<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…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@markgarrigan
Comment options

Answer selected by markgarrigan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants