victorjonsson / jQuery-Form-Validator

[DISCONTINUED] jQuery plugin that makes it easy to validate user input while keeping your HTML markup clean from javascript code.
972 stars 474 forks source link

Integration with TinyMCE? #324

Open TheCopacabanaMan opened 9 years ago

TheCopacabanaMan commented 9 years ago

I'm trying to integrate Validator with TinyMce TextArea, but validation is not working. Normal TextArea (without TinyMce) is working pretty good, but when i transform TextArea to TinyMce->TextArea, validator is not working. Is it possible integrate TinyMce? Thank you very grazie :)

widoz commented 8 years ago

Do you think there will be any news on this?

johnzhang2013 commented 8 years ago

@victorjonsson Hi so what is going on now about this issue? can not be sovled?

Please tell me asap. This feature is important to me .Thanks.

johnzhang2013 commented 8 years ago

Actually I also faced the similar problem. although my editor is not TinyMCE.

victorjonsson commented 8 years ago

Here is a quick and dirty fix http://jsbin.com/durelucehi/edit?html,output

What you need to do is to set validateHiddenInputs to true when setting up the validation.

$.validate({
   validateHiddenInputs: true
});

And also add the following script making sure that the textarea content is up to date when the form gets submitted.

function updateTextAreasWithContentFromTinyMCE() {
    $('textarea').each(function() {
        var content = getTinyMCEContentForTextarea(this);
        if (content !== undefined) {
            $(this).val(content);
        }
    });
}

function getTinyMCEContentForTextarea(textareaElem) {
    var id = textareaElem.id || textareaElem.name;
    for (i=0; i < tinyMCE.editors.length; i++) {
        if (tinyMCE.editors[i].id == id) {
           return tinyMCE.editors[i].getContent();
        }
    }
    return undefined;
}

$('form').on('submit', updateTextAreasWithContentFromTinyMCE);

The best thing would be to have a module fixing all this for you (and that doesn't require you to set validateHiddenInputs to true)

victorjonsson commented 8 years ago

Note: catch the blur event of the editor (tinymce.dom.Event.add(editor.getDoc(), 'blur') and trigger blur on the textarea-element