DROPDOWNLIST:
<div class="col-md-2">
<div class="form-group">
<label for="field-3" class="control-label">Priority</label>
<select id="lstpriority" class="selectpicker" data-live-search="true" data-style="btn-white">
</select>
</div>
</div>
Jquery验证:
$("#frmAddEdit").validate({
lstpriority: {
required: {
depends: function (element) {
return $("#lstpriority").val() == "";
}
}
},
messages: {
lstpriority: {
required: "Please select an option from the list",
},
},
submitHandler: function (form) {
abc();
return false;
}
});
下拉绑定:
function bindPrioritytype() {
$.ajax({
dataType: "json",
type: "POST",
url: 'AdminWeb.asmx/GetLOV',
data: 'id=0&type=PRIORITYTYPELOV',
async: true,
success: function (data) {
$("#lstpriority").append("").val("").html("");
$("#lstpriority").append($("<option></option>").val("").html("Select"));
$.each(data, function (key, val) {
$("#lstpriority").append($("<option></option>").val(val.TB_ID).html(val.TB_NAME));
});
$('#lstpriority').selectpicker('refresh');
}
});
}
我无法在提交时验证dropdownlist,即使我尝试添加所需的课程。我想验证下拉列表,请帮我修复此问题。
答案 0 :(得分:0)
尝试使用
lstpriority: {required: true}
而不是
lstpriority: {
required: {
depends: function (element) {
return $("#lstpriority").val() == "";
}
}
},
答案 1 :(得分:-1)
使用这段代码。您还可以在valueNotEquals: ""
中声明一些默认选择,例如选择..或选择,您可以将其更改为valueNotEquals: "Select"
完整代码
// configure your validation on a list
$("#frmAddEdit").validate({
rules: {
lstpriority: { valueNotEquals: "" }
},
messages: {
lstpriority: { valueNotEquals: "Please select an item!" }
}
});