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 🙂
Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024Digital marketers and app developers have tracked activity in apps and websites for yea...
By Ollie Mar 13, 2024February was an exciting month with Shopify Editions, informative webinars, and more! F...
By JasonH Mar 7, 2024