我有以下配置在按下提交按钮时验证表单:
$('#myForm').formValidation({
framework: 'bootstrap',
excluded: [':disabled'],
icon: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
title: {
validators: {
notEmpty: {
message: 'Title is required (max 128 characters)'
}
}
},
rating: {
validators: {
notEmpty: {
message: // Call function here? check for 0
}
}
}
}
});
评分字段是一个滑块,用户可以选择 0 到 5 之间的值
默认情况下它是 0,所以当我按下提交时它验证为有效,所以我需要创建一个自定义函数,如果它是 0,它将检查它的值,然后返回无效,否则返回 true。
html如下:
<input id="Rating" name="rating" data-slider-id='ex1Slider' type="text" data-slider-min="0" data-slider-max="5" data-slider-step="1" data-slider-value="" /> <span id="rate" style="margin-left:5%">0 / 5</span>
HTML 呈现时的外观,并引用 bootstrap-slider.js
<input id="Rating" type="text" data-slider-value="" data-slider-step="1" data-slider-max="5" data-slider-min="0" data-slider-id="ex1Slider" name="rating" data-fv-field="rating" style="display: none;" data="value: '0'" value="0">