首页 > 解决方案 > 双列表框禁用选择选项

问题描述

我正在使用从http://www.virtuosoft.eu/code/bootstrap-duallistbox/获得的 Bootstrap Dual Listbox

我正在使用 Thymeleaf 生成列表框选项。我有这样一个场景——在我的实体中有 BOOLEAN 列名 is_generated,如果 'is_generated=true' 意味着需要禁用基于条件的选项,这意味着用户无法选择特定选项,如HTML 属性 (disabled="true")

这是我的代码

 <form id="chargeslistformid" method="post" action="#" 
				 th:action="@{/savechargeslist}" th:object="${wrpAssignCharges}">
         
        <label>
            <select id="selectBox" multiple="multiple"
            name="selectedChargesList" class="selectpicker form-control" >
                <option  th:each="charge:${chargeslist}" 
                th:value="${charge.pkAssignId}" 
                th:text="${charge.chargeName}"
                th:selected="${previouslist.contains(charge)}"></option>
            </select>
        </label>
        
       
        
        <br/>
        <button id="chargeslistbtnid" th:type="submit" class="btn btn-info">Next</button>
    </form>

请帮帮我...在此先感谢

标签: htmlthymeleafbootstrap-duallistbox

解决方案


您可以使用 th:disabled 属性根据条件生成禁用属性:

<option
  ..
  th:disabled="${ /* condition, e.g. 1 < 2 or #object.property == ... */ }"
>
</option>

推荐阅读