I have a large form I'm presenting to the user using bootstrap tabs. On various of the tabs there are input fields that have a required="required"
attribute.
<!-- illustrative code only, with all the excess cruft elided -->
<form onsumbit="return somefunction(this);" method=post action="url">
<fieldset style="display: none;">
<!-- the hidden tab -->
<input required name="princess">
</fieldset>
<fieldset>
<input required name="goomba">
</fieldset>
<button type=submit>Save</button>
</field>
When there are blank required fields on non-current tabs and I click the submit button then the form is not submitted, but also the browser (Chrome v55) does nothing to alert the user to the blank required fields on the hidden tabs.
I put a onsubmit="return validateForm(this)"
handler on the <form…>
element thinking I could do something sensible there … but that handler is not being called. It appears the browser is checking all the non-visible inputs for validity and choking before calling the onsubmit
handler.
In the console I see an error message of "An invalid form control with name='princess' is not focusable." The princess
form control is on another tab (<input type=text name=princess required=required>
), and this error is firing before the onsubmit gets a chance to run.
So .. tackling this using <form onsubmit=…>
isn't the right strategy.
What can I do to run some js when the user attempts to submit the form and have that js gracefully do the necessary?