有两个类似的问题1和2,但他们通过ajax
提交表单,在我的Rails
应用中,我不想使用{{ 1}}加载并编写以下代码:
ajax
当<% content_for :javascript do %>
$("#new_answer_on_<%= _activity_parent_id %>").validate({
onsubmit: function(){
CKEditorUpdate();
return true;
},
errorClass: "my-error-class",
rules: {
"answer[content]": {required: true, minlength: 20}
}
});
function CKEditorUpdate(){
for(instance in CKEDITOR.instances)
CKEDITOR.instances[instance].updateElement();
}
<% end %>
的值为空时,上面的代码可以提醒错误消息,但是当有可用文本时:
当我第一次单击提交按钮时,我也会收到警告错误消息,直到我第二次单击它将内容提交给服务器。我不知道为什么?我该怎么做才能减少额外的点击次数?提前谢谢!
答案 0 :(得分:0)
通过将onsubmit
选项设置为函数,您可能已经破坏了正常的插件行为。 The onsubmit
option in the .validate()
method只能接受布尔值false
作为参数,而不是自定义函数。通过将其设置为false
,您将在单击submit
按钮时禁用验证触发器。 As per the documentation,“布尔值true
不是有效值”(已经是默认行为),也不能将其设置为自定义函数。
Review the documentation为CK编辑器更新功能选择合适的回调选项。