Thymeleaf 没有 select 禁用选项
Thymeleaf doesn't select disabled option
我正在使用 Materializecss select 形式 http://materializecss.com/forms.html#select 并且它需要正确的行为第一个选项被禁用和 selected。 Thymeleaf 忽略禁用的选项,尽管它是 selected。相反,它是 select 的第一个非禁用选项。
<div class="input-field col s6">
<select th:field="*{locale}" th:errorclass="invalid">
<option value="" selected="selected" disabled="disabled">Choose your option</option>
<option value="cs">Czech</option>
<option value="en">English</option>
</select>
<label>Locale</label>
</div>
捷克语是自动 selected,但我想看到 选择您的选项 改为 selected。
根据 Enigo 的评论,我通过将 select 元素中的 th:field
替换为 name
和 id
使其工作。我还在第一个选项中添加了 th:disabled
和 th:selected
以禁用它,默认情况下 selected。
<select name="locale" id="locale" th:errorclass="invalid" required="required">
<option value="" th:disabled="disabled" th:selected="selected">
Choose your option
</option>
<option value="cs">Czech</option>
<option value="en">English</option>
</select>
th:field 和 th:selected 不能同时工作。
为此删除 th:field 并手动替换 id 和 name 属性。
查看论坛thymeleaf-forum
我也遇到了同样的问题
我分享我的代码。
<div class="row">
<div class="input-field col s12">
<select id="doc" name="doc" th:with="doc=*{doc}">
<option value="" th:disabled="disabled" selected="true"
th:text="${status==true}? 'Seleccione tipo de documento' : ${doc}">Seleccione
tipo de documento</option>
<option th:each="tipoDoc : ${tipoDocs}" th:text="${tipoDoc}"
th:value="${tipoDoc}" />
</select>
<label>Documento</label>
</div>
萨鲁2
我正在使用 Materializecss select 形式 http://materializecss.com/forms.html#select 并且它需要正确的行为第一个选项被禁用和 selected。 Thymeleaf 忽略禁用的选项,尽管它是 selected。相反,它是 select 的第一个非禁用选项。
<div class="input-field col s6">
<select th:field="*{locale}" th:errorclass="invalid">
<option value="" selected="selected" disabled="disabled">Choose your option</option>
<option value="cs">Czech</option>
<option value="en">English</option>
</select>
<label>Locale</label>
</div>
捷克语是自动 selected,但我想看到 选择您的选项 改为 selected。
根据 Enigo 的评论,我通过将 select 元素中的 th:field
替换为 name
和 id
使其工作。我还在第一个选项中添加了 th:disabled
和 th:selected
以禁用它,默认情况下 selected。
<select name="locale" id="locale" th:errorclass="invalid" required="required">
<option value="" th:disabled="disabled" th:selected="selected">
Choose your option
</option>
<option value="cs">Czech</option>
<option value="en">English</option>
</select>
th:field 和 th:selected 不能同时工作。 为此删除 th:field 并手动替换 id 和 name 属性。
查看论坛thymeleaf-forum
我也遇到了同样的问题
我分享我的代码。
<div class="row">
<div class="input-field col s12">
<select id="doc" name="doc" th:with="doc=*{doc}">
<option value="" th:disabled="disabled" selected="true"
th:text="${status==true}? 'Seleccione tipo de documento' : ${doc}">Seleccione
tipo de documento</option>
<option th:each="tipoDoc : ${tipoDocs}" th:text="${tipoDoc}"
th:value="${tipoDoc}" />
</select>
<label>Documento</label>
</div>
萨鲁2