【发布时间】:2015-09-29 16:20:38
【问题描述】:
我使用 JQuery 和 BootstrapValidator 0.5.2 进行表单验证(目前我坚持使用旧版本)。 我想验证一个 Ace 编辑器字段 (http://ace.c9.io),它不能为空。 验证工作正常,问题是我无法手动更新字段验证状态。 任何人都知道如何访问 Ace 编辑器字段的引导验证功能? 基本上我的代码如下:
<div id="text" name="text" class="ace-editor" data-bv-field="text"></div>
$('#form').formValidation({
fields: {
'text': {
validators: {
callback: {
// check content of ace editor
message: 'Mandatory',
callback: function(value, validator) {
var editor = ace.edit('text'),
ok = (editor.session.getValue() != ''),
status = (ok) ? 'VALID' : 'INVALID';
// gives error: $(...).data(...) is undefined
//$('#text').data('bootstrapValidator').updateStatus('text', status, null);
// gives error TypeError: this.options.fields[b] is undefined in bootstrapValidator.min.js
$('#text').bootstrapValidator().data('bootstrapValidator').updateStatus('text', status, null);
return ok;
}
}
}
}
});
【问题讨论】:
标签: jquery twitter-bootstrap validation ace-editor