There are two similar questions 1 and 2, but they submit the form through ajax
, in my Rails
app, I don't want to use ajax
loading and write the following code:
<% 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 %>
The above code can alert error message when value of the textarea
is empty, but when there is the available text:
When I click submit button first time I also get alert error message, until I click it second time it will submit the content to the server. I don't know why? What should I do for reducing the additional click? Thanks in advance!