【发布时间】:2019-10-17 18:51:12
【问题描述】:
我正在尝试验证使用 th:each 创建的单选按钮的输入。 在 html 中的输入输出中使用 th:field checked="checked" 这使得一个单选按钮被选中,这是我不想要的。如果我输入 name="field" 则不会发生这种情况,但是不会发生对字段的验证,因为我不会使用 th:field。
<form th:action="@{/dosomething}" th:object="${Object}" method="post">
<div th:each="op : *{options}">
<input type="radio" th:field="*{options}" th:value="${op.id}" th:id="${opStat.index}"/>
<label th:for="${opStat.index}" th:text="${op.optiontext}">Option Text</label>
<button type="submit">Next</button>
</form>
<form action="/dosomething" method="post">
<div>
<input type="radio" value="1" id="0" name="options" checked="checked"/>
<label for="0">A</label>
</div>
<div>
<input type="radio" value="3" id="1" name="options" checked="checked"/>
<label for="1">B</label>
</div>
<div>
<input type="radio" value="4" id="2" name="options" checked="checked"/>
<label for="2">C</label>
</div>
<div>
<input type="radio" value="2" id="3" name="options" checked="checked"/>
<label for="3">D</label>
</div>
<button type="submit">Next</button>
</form>
【问题讨论】:
标签: thymeleaf