开发者

tinyMCE not working with jQuery Validation plug-in via javascript updates

开发者 https://www.devze.com 2023-04-12 11:23 出处:网络
I have Validation working across a large form (I fire it several times before Submit to check sections of the form), and a tinyMCE editor working in 1 textarea. I want to move the contents of the tiny

I have Validation working across a large form (I fire it several times before Submit to check sections of the form), and a tinyMCE editor working in 1 textarea. I want to move the contents of the tinyMCE iframe into the textarea before (that's the key here - before) the Submit button is pressed so that the contents can be validated in the section before Submit.

I've used tinyMCE.triggerSave(); in several ways to move contents and then fire Validation before Submit. None work. I am beginning to believe that tinyMCE contents cannot be moved by any Javascript, rather contents move only via the Submit button, but I don't see that stated anywhere.

In tinyMCE, I've tried onchange_callback: and handle_node_change_callback: to fire functions with triggerSave and other saving commands. I can get the contents of tinyMCE to validate when I press Submit twice (others have noted this peculiarity), but not in any other way.

Also, when errors are corrected in tinyMCE, Validation does not revalidate until Submit is pressed. It should re-validate in real time, as Validation is designed to do.

2 questions -

Anyone know how to move tinyMCE contents into the textarea without hitting Submit?

Does CKEditor allow updates other than via Submit, and if so, where's a tutorial or example?

Here's an example of code that is supposed to be triggered by tinyMCE's onchange_callback, but only triggers upon the second click on Submit.

function tinyMCESetValue(inst)
{
var content = tinyMCE.activeEditor.getContent();
if (tinyMCE.activeEditor.isDirty()) {tinyMCE.triggerSave(true, true);}
// other save expressions that have been tried - with same results
//$("#selector").val(content);
//$("textarea.tin开发者_StackOverflow中文版ymce").val(content);
//tinyMCE.triggerSave();
//ed.save();
alert("some change"); //does not fire
}

In response to Thariama's comment, the above code is supposed to be triggered by the tinyMCEinit option of onchange_callback: "tinyMCESetValue",. I also have the following code in a JS section that does everything else correctly. The alert always shows 'undefined'. See any problem? Where else should I look/try? What tests can I do - I'm not getting useful info from Firebug.

if ($( "#sections" ).accordion( "option", "active" ) == 1)  //if the second Accordion section
{
    var content = tinyMCE.activeEditor.getContent(); //get the content from the tinyMCE iframe
        if (tinyMCE.activeEditor.isDirty()) //if the contents of tinyMCE have changed}
        {tinyMCE.triggerSave(true, true);} //put contents in the textarea
    alert("|" + $("#detailedDescription").val() + "|tinyMCEval");
    if (i == 7) {$("#detailedDescription").rules("add", {validCharsCheck: true});}
}


I found a workaround for this problem .
i changed jquery.validate.js file.

this.submit(function (event) 
{ 
    if (window.tinyMCE != undefined) 
    { 
        tinyMCE.triggerSave(); 
    }
    .
    .
    .
})

this solution only works for tinymce.


hi if you are not getting client side validation on form submit time when you are using TINYMCE i have one solution but this is not proper way but it work fine you can get all required validation on form submit time please check this code or example THIS IS CLIENT SIDE VALIDATION @Html.LabelFor(model => model.txtAboutCompany, new { @class = "required" }) @Html.EditorFor(model => model.txtAboutCompany)

THIS IS JQUERY

$("#BusinessProfile").click(function () {
    var aboutC = $("#txtAboutCompany").val()
    var pinfo = $("#txtProductinfo").val();
    if (aboutC == "" && pinfo == "") {
        $("#AC").append("").val("").html("Please enter about company")
        $("#PI").append("").val("").html("Please enter product information")
        $("#bpform").valid();

        return false;
    } else if (aboutC == "") {
        $("#PI").append("").val("").html("")
        $("#AC").append("").val("").html("Please enter about company")
        $("#txtAboutCompany").focus();

        $("#bpform").valid();
        return false;
    } else if (pinfo == "") {
        $("#AC").append("").val("").html("")
        $("#PI").append("").val("").html("Please enter product information")
        $("#txtProductinfo").focus();
        $("#bpform").valid();

        return false;
    }
    else {
        $("#AC").append("").val("").html("");
        $("#PI").append("").val("").html("");
        //return true;
        $("#bpform").validate();
    }
    });

try it

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号