I have a text-area
<td><textarea id="event-body" name="body">
<p class="error"></p>
That is integrated with CKEDITOR
CKEDITOR.replace("event-body")
And jquery validate plugin. And the code is like this
$('#event').validate({
rules:{
name:{
required: true
},
},
messages:{
body:{
required: "event body is required"
}
},
errorPlacement: function(error, element){
$(element).each(function (){
$(this).parent('td').find('p.error').html(error);
})
});
The code works just fine but when I type into my textarea
element, I still get the error message until I click it twice. i.e. I have to submit my page twice so that I don't error message even if textarea
is not empty.
Isn't there a way to validate it smoothly(without having to click it twice).
Put this in submit button mousedown() event:
IF your using SPRY, This is what worked for me....
I would prefer to update each instance on blur event, so you don't need to change anything on your submit function! :)
jQuery validator only validate input fields that are visible but CKEDITOR makes the textarea hidden preventing it from being validated.
jQuery .validate() function provides "onsubmit" option to perform custom action before validation. By default it is set to true. I have used it in my project and it works very well.
This is a cleaner and much easier to understand approach. Refer http://jqueryvalidation.org/validate#onsubmit
I've combined your sugestions and make this little cheat that works with no problem.
My code:
On my .css file, I forced my to be like this:
And my .js validation is the normal format: