'How do I fill in the input type= "time" field in Thymeleaf?
The Spring-Boot + Thymeleaf project does not fill in the input type= "time" field When opening the html form. That's how it works:
<input type="time" class="form-control" id="inputTime" th:value=${CarEntity.timeOperation} required>
And here it is:
<input type="time" class="form-control" id="inputTime" th:field="*{timeOperation}" required>
Or so:
<input type="time" class="form-control" id="inputTime" th:field="*{timeOperation}" th:value=${CarEntity.timeOperation} required>
The field remains empty. And if I use <input type= " text> then everything works fine.
<form id="f-pr-03" th:method="POST" th:action="@{/edit/{id}(id=${carEntity.getId()})}" th:object="${carEntity}">
That's how everything works and displays and reads.
<label for="inputName">Input name</label>
<input type="text" class="form-control" id="inputName" th:field="*{name}" required>
But this is not displayed
<label for="inputPTTime">Input time</label>
<input type="time" class="form-control" id="inputPTTime" th:field="*{timeOperation}" max="17:50" min="00:01" required>
And this is how it is displayed, but not transmitted by the POST method
<label for="inputPTTime">Input time</label>
<input type="time" class="form-control" id="inputPTTime" th:value=${CarEntity.timeOperation} max="17:50" min="00:01" required>
<button type="submit" name="action">Save</button>
</form>
Solution 1:[1]
I don't if it is still relevant since it's benn a while. Thymeleaf provides a special attribute th:field responsible for binding input fields with a property in the bean class. This attribute behaves differently depending on whether it is attached to. Thymeleaf supports all-new input types introduced in HTML5 such as type="color" or type="datetime".
Please check this out for more info:
https://frontbackend.com/thymeleaf/working-with-forms-in-thymeleaf
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | k9ne257 |