1

Hi I used jQuery Validation to validate my form before submit it.

And I intercept submit handler in this way:

  <script type="text/javascript">
   <![CDATA[

        $(function() {
            $( "#_${sec_form}_id" ).validate({
                errorElement: "span",
                submitHandler: function(form) {
                    form.submit();
                }
            });

          $.validator.addMethod(
                "validator",
                function(value, element, regexp) {
                    if(value != null && value.trim()!=""){
                        var re = new RegExp(regexp);
                        return re.test(value);
                    }else{
                        return true;
                    }
                },
                "Inserire un valore coerente."
            );
        });
    ]]>
   </script>

In that form I have some Ckeditor fields, but when I submit form, I lose all edits to ckeditor fields.

If I delete my submit handler, all works.

Have you any idea about it?

Thank you

Sparky
  • 98,165
  • 25
  • 199
  • 285
PaolaG
  • 814
  • 1
  • 11
  • 27

1 Answers1

0

You can copy your CKEditor fields' values to an actual textarea before submitting so that your error will be ignored.

CKEDITOR.on('instanceReady', function () {
    $.each(CKEDITOR.instances, function (instance) {
        CKEDITOR.instances[instance].document.on("keyup", CK_jQ);
        CKEDITOR.instances[instance].document.on("paste", CK_jQ);
        CKEDITOR.instances[instance].document.on("keypress", CK_jQ);
        CKEDITOR.instances[instance].document.on("blur", CK_jQ);
        CKEDITOR.instances[instance].document.on("change", CK_jQ);
    });
});

function CK_jQ() {
    for (instance in CKEDITOR.instances) {
        CKEDITOR.instances[instance].updateElement();
    }
}

To try this, check this fiddle: http://jsfiddle.net/ryleyb/QcJ57/

For more information check this question: Jquery validation not working with ckeditor

Community
  • 1
  • 1
Burak
  • 5,252
  • 3
  • 22
  • 30