Shopify themes, liquid, logos, and UX
hi,
i have use required attribute in my select filed even after this it's not validating the field, when i click on button without selecting any value in select field than button clicked and form got submitted. Required not working it's not showing any error if i don't have any value in the select field, and it's allow form to submit with blank value of select tag.
How i can put validation on select that if select does not have any value than it must show error and resist the form to submit without any value.
Hello manuY,
I've worked as freelancer on the same theme.
The select element could be a bit tricky.
Try something like this:
<label for="size">Choose a size:</label>
<select name="size" required>
<option value="">None</option>
<option value="Small" {% if cart.attributes["size"] == "Small" %} selected {% endif %} >Small</option>
<option value="Medium" {% if cart.attributes["size"] == "Medium" %} selected {% endif %} >Medium</option>
<option value="Big" {% if cart.attributes["size"] == "Big" %} selected {% endif %} >Big</option>
</select>
Note: if your form in the cart-template.html has a "novalidate" attribute, be sure to remove it.
Also, check the w3schools reference here: https://www.w3schools.com/tags/att_select_required.asp
Let me know 🙂
Are you ready to take your business to the next level? Look no further than the latest ...
By SarahF_Shopify Apr 15, 2024We’re keeping the ball rolling to make sure you’re always ahead of the game. So buckle ...
By JasonH Apr 8, 2024Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024