有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在Thymeleaf中创建必需的下拉列表/选择

好吧,我读了很多关于这方面的书,我似乎找不到解决办法

我有一个下拉列表,我想确保有人在继续和提交表单之前更改/选择答案。如果他们试图提交而未选择select选项,我希望引发警报

我尝试了多种必选的方法,例如:

th:required="required"th:required="true"required="required"required="true"。。。我甚至在我的模型中尝试了@NoValidate注释

如何使此下拉列表成为必需?谢谢

<form class="ui form" th:object="${directBind}" th:action="directBind" method="post" style="padding:0 10px;"> <h4>Customer Setup</h4> <div class="row"> <label >Contact Name (First/Last):</label> <input type="text" th:field="*{contactName}" required="true" /> </div> <div class="row"> <label for="formAddress">Address:</label> <input type="text" id="formAddress" th:field="*{formAddress}" required="true"/> </div> <div class="row"> <label for="phoneNumber">Phone Number:</label> <input type="text" id="phoneNumber" th:field="*{phoneNumber}" required="true"/> </div> <div class="row"> <label for="email">Email:</label> <input type="email" id="email" th:field="*{email}" required="true"/> </div> <div class="row"> <label for="website" style="margin-top: 1em;"> Website:</label> <input type="text" id="website" th:field="*{website}" required="true"/> </div> <div class="row"> <label for="nameInsured">Name Insured:</label> <input type="text" id="nameInsured" th:field="*{insuredName}" required="true"/> </div> <div class="row"> <label>Business with Agency:</label> <div th:each="businessAgency : ${businessAgencies}"> <input type="checkbox" th:field="*{businessAgencyList}" th:value="${businessAgency}"/> <label th:text="${businessAgency}">Business with Agency</label> </div> </div> <div class="row"> <label>Executive:</label> <th:block th:switch="${loggedUser==null or loggedUser.client==null }"> <span th:case="false" th:text="${loggedUser.client.getExecutive()}"></span> <span th:case="true"> Not Applicable </span> </th:block> <th:block th:switch="${loggedUser==null or loggedUser.client==null }"> <input th:case="false" type="hidden" name="executive" class="executive" th:value="${loggedUser.client.getExecutive()}" /> <input th:case="true" type="hidden" name="executive" class="executive" value="Not Applicable" /> </th:block> <label style="font-size: 1.25rem; margin-left: 10px;"> <input type="checkbox" id="directBox" th:field="*{directBox}"/> Direct </label> </div> <div class="row" style="display: inline-block; margin-top:0;"> <p>Service Level:</p> <label> <input type="checkbox" id="serviceLevel" th:field="*{serviceLevel}"/> Affiliate Serviced</label> </div> <div class="row"> <label for="affiliateRep">Affiliate Designated Representative:</label> <input type="text" id="affiliateRep" th:field="*{affiliateRep}" required="true" /> </div> <div id="amsSection"> <h4 style="display: inline;">AMS360 Policy Setup</h4> <input type="submit" formnovalidate="formnovalidate" name="addPolicy" class="btn btn-default" style="margin-left: 1rem; margin-bottom: 1rem;" value="Add Another Policy Line"/> </div> <div class="col-sm-12"> <hr/> <table class="table table-striped AMSTable" data-classes="table-no-bordered" data-striped="true" data-show-columns="true" data-pagination="true"> <thead> <tr> <th>Policy Number</th> <th>Policy Term Start Date</th> <th>Policy Term End Date</th> <th>Line of Coverage</th> <th style="width:150px;">Parent Company<i class="tooltipped material-icons" data-position="top" data-tooltip="Parent Company indicates Standard Carrier, Wholesaler, or MGA">info_outline</i></th> <th style="width:150px;">Writing Company<i class="tooltipped material-icons" data-position="top" data-tooltip="Writing Company indicates carrier paper specific to policy">info_outline</i></th> <th>Bill Type</th> <th>Quote Premium</th> <th>Commission</th> <th><a class="trigger btn btn-docModal"><span class="fa fa-upload"></span></a></th> </tr> </thead> <tbody> <tr name="newRow" th:each="ams360Policy,stat : ${ams360Policies}" th:value="${stat.index}"> <td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].policyNumber}"/></td> <td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].policyTermDateStart}"/></td> <td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].policyTermDateEnd}"/></td> <td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].lineOfCoverage}"/></td> <td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].parentCompany}"/></td> <td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].writingCompany}"/></td> <td id="billTypeCell"> <div th:each="billType : ${billTypeList}"> <input type="checkbox" th:field="*{ams360Policies[__${stat.index}__].billTypeOptions}" th:value="${billType}" value="off"/> <label th:text="${billType}" id="billTypeLabel"></label> </div> </td> <td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].quotePremium}"/></td> <td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].commission}"/></td> <td class="text-right"> <button type="Submit" formnovalidate="formnovalidate" name="removeRow" th:value="${stat.index}" class="btn btn-danger" ><span class="fa fa-trash"></span></button></td> </tr> </tbody> </table> <table> <tr> <td id="appendFile"></td> </tr> </table> </div> <h4>PMA Setup</h4> <div class="row" sec:authorize="hasAnyRole('ADMIN','USER')"> <label>Sub Brand:</label> <th:block th:switch="${loggedUser==null or loggedUser.client==null }"> <span th:case="false" th:text="${loggedUser.client.getLegalName()}" ></span> <span th:case="true">Not Applicable</span> </th:block> <th:block th:switch="${loggedUser==null or loggedUser.client==null}"> <input th:case="false" type="hidden" name="subBrand" class="subBrand" th:value="${loggedUser.client.getLegalName()}" /> <input th:case="true" type="hidden" name="subBrand" class="subBrand" value="Not Applicable" /> </th:block> </div> <!-- Business Class Drop Down Field Below: --> <div class="row"> <label>Business Class: </label> <div > <select class="form-control" th:field="*{businessClasses}"> <option th:each="businessClass : ${businessClassList}" th:value="${businessClass}" th:text="${businessClass}"></option> </select> </div> </div> <div class="row"> <label for="descriptionOfOps">Description of Operations:</label> <input type="text" id="descriptionOfOps" th:field="*{descriptionOfOps}" required="true" /> </div> <div class="formFooter"> <input id="send" type="submit" value="send" name="send" class="btn btn-success finish" data-loading-text="Sent!" disabled="true"/> </div> </form>

共 (0) 个答案