Thymeleaf select required not working?

thymeleaf

Since last few days trying to add select “required” attribute in my Thymeleaf project.  Neither of these works in Thymeleaf:

  • <select required=”required”>
  • <select required=’required’>
  • <select required=required>
  • <select required=””>
  • <select required=”>
  • <select required>

In this tutorial I’m gonna show how to achieve this.

Let’s copy the code from below:

<select th:name="someName" class="form-control" id="someID" th:required="true">
    <option value="">Select Category</option>
    <option th:each="model: ${someModel}" th:value="${model.id}"
            th:text="${model.Title}"></option>
</select>

Please note that, first/default option value must be set to “” if you put “0” it won’t work!

That’s all! We’re done!
If you’ve any confusion please let me know 🙂