Required attribute | Form Validation ignored
Hey, for some reason javascripts skips form validation, without it validation fully takes place. I have to submit form without page reload, thats why theres preventDefault:
14 Replies
For more info,
When I just select one of the radio buttons
it proceeds without showing err
even though other fields have rquired attribute
thats weird too
can you make a live example?
sure
without it, it's just speculations and guestimations
not actual answers
alright
@ἔρως
It's fixed...
it was an error in js?
For validation to take place, I had to replace
bookFormSubmit.addEventListener("click", (event) => { ...with bookForm.addEventListener("submit"...
lol
before the event listener was on the submit button
not the form itself
that explains it i guessthat does explain it
you're not supposed to attach click events on submit buttons on forms
I will keep it in mind next time!
also, the
event.preventDefault() has to be at the topI saw in mdn docs it was at bottom
and you can use
let data = new FormData(event.currentTarget) to get all the form data
i always put it at the topbut I think top is the right way coz claude was putting it at top too (i rarely use chatbots for webdev :/ )
ohhhh
k thanks
you're welcome