我有一个Rails应用程序,在这个应用程序中,我使用编辑器进行富文本输入。该表单被放置在一个引导模式中。我希望在用户输入时验证(存在),如果字段为空,则显示验证错误。我使用BootstrapValidator作为验证部分。我目前没有收到任何redactor文本区域的验证消息。
代码的相关部分如下:
= form_for idea, remote: remote, html: {role: :form, "data-model" => 'idea', multipart: true} do |f|
# This field / validation works
.form-group
= f.label :title, "Title", :class => "required"
= f.text_field :title, :class => "form-control"
# This does not
.form-group
= f.label :description, :class => "required"
= f.text_area :description, :class => "form-control big-text-area redactor"Javascript是这样的:
:javascript
$('#new_idea').bootstrapValidator({
message: 'This value is not valid',
feedbackIcons: {
valid: 'fa fa-check-square',
invalid: 'fa fa-warning',
validating: 'fa fa-circle-o-notch spin'
},
fields: {
"idea[title]": {
validators: {
notEmpty: {
message: 'The title is required'
}
}
},
"idea[description]": {
validators: {
callback: {
message: 'The idea description is required',
callback: function(value, validator) {
# NOTE: This part of the code never get called
var code = $('[name="idea[description]"]').code();
return (code !== '' && code !== '<p><br></p>');
}
}
}
}
}
})
$('.redactor').redactor({
keyupCallback: function (e) {
validateEditor();
}
});
function validateEditor() {
$('#new_idea').bootstrapValidator('revalidateField', "idea[description]");
};有什么想法可以让我的验证工作吗?
发布于 2014-10-05 16:17:37
我遇到了一些类似的东西,当我使用红演员,所以这可能会有所帮助。在我的例子中,我的文本区域中有一个更改侦听器,它是Redactor绑定到的(与我认为正在做的类似的方法),但问题是Redactor正在吃原始文本区域上的更改事件。为了解决这个问题,我在初始化Redactor插件时实现了以下内容。
var $mytextarea = $('selector-for-textarea');
$mytextarea.redactor({
changeCallback: function( html ) {
$mytextarea.trigger( 'change' );
}
});希望这能帮上忙干杯。
https://stackoverflow.com/questions/26204107
复制相似问题