我尝试使用required =" true"和th:required =" required"并且仅使用必需(因为我使用百里香叶时抛出错误),添加空值值=""但仍然无法正常工作。我尝试添加值="哑& #34;和价值=""对于第二个选项标签,同样......没有工作并尝试使用bootstrap验证器。当我提交表单时,我有一个弹出窗口,如果我按OK,则提交表单。 我正在使用chrome,我有另一种形式,我正在使用输入+必需,并且它正在工作。 任何帮助将不胜感激。谢谢!
<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.");
}
}
});
};
UPDATE 控制器负责填充&#34; institutieList&#34;
@RequestMapping(value="/create", method=RequestMethod.GET)
public String createAppointmentPost(Model model, @ModelAttribute("city")
City city, @ModelAttribute("agency") Agency agency, Principal principal){
User user = userService.findByUsername(principal.getName());
Appointment appointment=new Appointment();
model.addAttribute("appointment", appointment);
model.addAttribute("dateString", "");
model.addAttribute("cities", cityService.findAll());
model.addAttribute("institutieList", instituteService.findAll());
model.addAttribute("myFiles", userService.listAllUploadedFiles(user));
return "appointment";
}
更新2: 问题在于提交按钮,我忘了输入=&#34;提交&#34;。
答案 0 :(得分:0)
正确使用所需的isn不需要=&#34; true&#34;但只需要,如:
<select class="form-control" required
th:value="${appointment.institutie}"name="institutie"
id="institutie">