验证 Bootstrap Select - 由 AJAX 加载
Validation Bootstrap Select - Loaded by AJAX
我正在尝试向 bootstrap-select 添加验证,但不知何故验证不起作用
首先,我 select 从其他 bootstrap select 获取主要类别,然后
子类别按预期加载 ajax...
<select name="code" class="form-control" id="code">
</select>
JS
<script type="text/javascript">
$('#code').on('change', function(e) {
// Revalidate the date field
$('#createSubCode').formValidation('revalidateField', 'code');
});
</script>
更多
<script type="text/javascript">
$(document).ready(function() {
$('#createSubCode')
.formValidation({
framework: 'bootstrap',
icon: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
title: {
validators: {
notEmpty: {
message: 'The title is required'
}
}
},
code: {
validators: {
notEmpty: {
message: 'The code is required'
}
}
}
}
})
});
</script>
所以每当我 select 说需要代码!验证未通过!
我找到问题了
AJAX
来自
$.each(data,function(index,subCateObj){
$('#code').append('<option>'+subCateObj+'</option>');
});
到
$.each(data,function(index,subCateObj){
$('#code').append('<option value='+subCateObj+'>'+subCateObj+'</option>');
});
我正在尝试向 bootstrap-select 添加验证,但不知何故验证不起作用
首先,我 select 从其他 bootstrap select 获取主要类别,然后
子类别按预期加载 ajax...
<select name="code" class="form-control" id="code">
</select>
JS
<script type="text/javascript">
$('#code').on('change', function(e) {
// Revalidate the date field
$('#createSubCode').formValidation('revalidateField', 'code');
});
</script>
更多
<script type="text/javascript">
$(document).ready(function() {
$('#createSubCode')
.formValidation({
framework: 'bootstrap',
icon: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
title: {
validators: {
notEmpty: {
message: 'The title is required'
}
}
},
code: {
validators: {
notEmpty: {
message: 'The code is required'
}
}
}
}
})
});
</script>
所以每当我 select 说需要代码!验证未通过!
我找到问题了
AJAX
来自
$.each(data,function(index,subCateObj){
$('#code').append('<option>'+subCateObj+'</option>');
});
到
$.each(data,function(index,subCateObj){
$('#code').append('<option value='+subCateObj+'>'+subCateObj+'</option>');
});