I have 2 forms reservation info form & customer info form.
I've set all of the input fields as required.
I also have a button that is only supposed to hide the first form and show the second once clicked. I have it as type="button"
since I'm not really submitting it anywhere.
I created a jQuery click()
handler for my button.
My Issue is that I've tested the button and it completely bypasses the required validation of the input fields. It shows the second form and hides the first regardless of empty input fields.
I would like it if the forms validated the required attribute, so there are no blank input fields before they hide/show.
script.js
$(function () {
$('#reservation-submit-btn').click(function () {
$('#reservation-info-form').hide('slow');
$('#customer-info-form').show('slow');
})
})
HTML file
<div id="reservation-info-form" class="reservation-form-wrapper" aria-labelledby="reservation-form-label">
<div id="reservation-form-label"><h2>Make A Reservation</h2></div>
<form id="reservation-form" aria-label="reservation form" method="post" autocomplete="off">
<label for="res-date"></label>
<input
aria-label="reservation date"
type="date"
name="res-date"
id="res-date"
placeholder="current date"
required
/>
<label for="res-time"></label>
<input
aria-label="reservation time"
type="time"
name="res-time"
id="res-time"
placeholder="current time"
required
/>
<label for="res-party-size"></label>
<input
aria-label="party size"
type="number"
min="1"
max="9"
name="res-party-size"
id="res-party-size"
placeholder=0
required
/>
<button type="button" id="reservation-submit-btn" class="submit-btn">
Find a Table
</button>
I realize that creating a click handler just adds a method to the button and doesn't consider all of the input fields or the required attributes. So my real question is how do I do this in a way where I create the effects I need from the button while not bypassing the required attribute on the input fields?