brief-sugar-79424
02/20/2022, 9:01 AMbrief-sugar-79424
02/20/2022, 9:03 AMgorgeous-airport-54386
02/20/2022, 11:03 AMbland-coat-6833
02/20/2022, 11:15 AMbig-airline-13935
02/20/2022, 4:53 PMbig-airline-13935
02/20/2022, 4:54 PMnumerous-application-19425
02/20/2022, 5:27 PMhx-post submits the form even if it's invalid - so I guess instead of event.preventDefault() I need to prevent htmx from submitting - maybe I just try to find a way to disable the "send" button as long as the form is invalid?!
js
if (!form.checkValidity()) {
// something that prevents htmx from posting?!
event.preventDefault()
event.stopPropagation()
}
I'd like to see the usage of htmx:validation:validate in plain JS - hyperscript breaks my brain right now 😄hundreds-camera-24900
02/20/2022, 5:39 PMhundreds-camera-24900
02/20/2022, 5:40 PMadamant-exabyte-92636
02/20/2022, 5:40 PMhundreds-camera-24900
02/20/2022, 5:40 PMhundreds-camera-24900
02/20/2022, 5:40 PMhundreds-camera-24900
02/20/2022, 5:45 PMhundreds-camera-24900
02/20/2022, 5:45 PM<form hx-get="{% url 'user:account_welcome' %}"
hx-swap="outerHTML"
hx-target="#account-box"
class="flex flex-col space-y-10">
<div>
<label for="email" class="block text-sm font-medium text-gray-700">Email address</label>
<div class="mt-1">
<input id="email"
name="email"
type="email"
autocomplete="email"
required
class="appearance-none block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm">
</div>
</div>
<button class="">Continue</button>
</form>hundreds-camera-24900
02/20/2022, 5:45 PMhundreds-camera-24900
02/20/2022, 5:46 PMhundreds-camera-24900
02/20/2022, 8:20 PMhundreds-camera-24900
02/20/2022, 8:20 PMhundreds-camera-24900
02/20/2022, 8:21 PMhundreds-camera-24900
02/20/2022, 8:23 PMquiet-angle-80724
02/21/2022, 6:56 AMeager-tiger-27508
02/21/2022, 7:25 AMeager-tiger-27508
02/21/2022, 7:30 AMnumerous-application-19425
02/21/2022, 8:45 AM<form novalidate> and that's why it uses extra JS to prevent the form from submitting.
> For custom Bootstrap form validation messages, you’ll need to add the novalidate boolean attribute to your . This disables the browser default feedback tooltips, but still provides access to the form validation APIs in JavaScript. Try to submit the form below; our JavaScript will intercept the submit button and relay feedback to you. When attempting to submit, you’ll see the :invalid and :valid styles applied to your form controls.
>
I'll dig depper - you helped me a lot! Thanks!numerous-application-19425
02/21/2022, 10:24 AMbs-send and then execute the trigger htmx.trigger(form, "bsSend"); on form.checkValidity() in my JS.
here is a fiddle https://jsfiddle.net/1Lrtg34e/4/ (I hope I did it right, with the inclusion of demo.htmx.org please feel free to add a correction or how to do it better).
[1] https://discord.com/channels/725789699527933952/725789747212976259/925877952523161720
[2] https://getbootstrap.com/docs/5.1/forms/validation/#custom-stylesnumerous-application-19425
02/21/2022, 10:26 AMnumerous-application-19425
02/21/2022, 11:03 AMquiet-angle-80724
02/21/2022, 12:33 PMnumerous-application-19425
02/21/2022, 1:37 PMmysterious-toddler-20573
02/21/2022, 2:34 PM