Html 带有标记select的必需属性不起作用

Html 带有标记select的必需属性不起作用,html,twitter-bootstrap,thymeleaf,Html,Twitter Bootstrap,Thymeleaf,我尝试使用required=true和th:required=required并使用only required这会引发一个错误,因为我正在使用thymeleaf,添加了空值value=,但仍然不起作用。我尝试了第二个选项标记added value=dumb和value=,same…不起作用,并尝试使用引导验证程序。当我提交表单时,我有一个弹出窗口,如果我按OK,则提交表单。 我使用的是chrome,我有另一个表单,我使用的是input+required,它在那里工作。 任何帮助都将不胜感激。谢谢

我尝试使用required=true和th:required=required并使用only required这会引发一个错误,因为我正在使用thymeleaf,添加了空值value=,但仍然不起作用。我尝试了第二个选项标记added value=dumb和value=,same…不起作用,并尝试使用引导验证程序。当我提交表单时,我有一个弹出窗口,如果我按OK,则提交表单。 我使用的是chrome,我有另一个表单,我使用的是input+required,它在那里工作。 任何帮助都将不胜感激。谢谢

<form th:action="@{/appointment/create}" method="post" id="appointmentForm">
<div class="form-group">
                <label for="location">Alege institutia:</label>

                <select class="form-control" required="required" 
                th:value="${appointment.institutie}"name="institutie" 
                id="institutie">

                 <option value="" disabled="disabled" selected="selected" > 
                 -- alege institutia --</option>
                 <option th:each="institutie : ${institutieList}"  
               th:text="${institutie.numeInstitutie}" ></option>

               </select>
</div></form>


            var confirm = function() {
            bootbox.confirm({
                title : "Confirmare programare",
                message : "Doriti sa creeati programarea?",
                buttons : {
                    cancel : {
                        label : '<i class="fa fa-times"></i> Nu'
                    },
                    confirm : {
                        label : '<i class="fa fa-check"></i> Da'
                    }
                },
                callback : function(result) {
                    if (result == true) {
                        $('#appointmentForm').submit();
                    } else {
                        console.log("Confirmare anulata.");
                    }
                }
            });
        };
更新2:
问题在于提交按钮,我忘记了type=submit。

required的正确用法不是required=true,而是required,如下所示:

<select class="form-control" required 
            th:value="${appointment.institutie}"name="institutie" 
            id="institutie">

将第一个选项设置为selected=selected。那么您的值是必需的,但它已设置为该值。为什么您的第一个选项被禁用并被选中?禁用是因为我不想选择它并被选中,因为我想先显示它。就像第一个选择是选择。如果我不使用selected,下拉列表将显示DB中的First值。好的,我在没有Thymeleaf的情况下尝试了这个,它工作正常。如果未设置此值,我将无法提交表格。我不熟悉Thymeleaf。谢谢!我不明白他为什么不跟百里来夫合作。由于标签输入正在工作,我认为这与弹出窗口有关。如果我可以问的话,为什么要投反对票?请参阅使用Thymeleaf是必需的=据我所知是必需的。如果我按照你的建议使用required,将抛出一个错误。什么错误?使用required=required不会对Thymeleaf执行任何操作,因为它不会以th:开头。我在表单中使用了plain required,它对我很有用。此错误:error 7616-[nio-8181-exec-3]o.thymeleaf.templateparser.ErrorHandler:[thymeleaf][http-nio-8181-exec-3]解析org.xml.sax.SAXParseException时出现致命错误:与元素类型select关联的属性名必须后跟“=”字符。我没有投你反对票,但你的评论没有用。无论如何谢谢你!那真奇怪。明天当我再次访问我的代码并发布一个工作示例时,我将查看它。
<select class="form-control" required 
            th:value="${appointment.institutie}"name="institutie" 
            id="institutie">