Checking Multiple TinyMCE Editor

I have a form with several TinyMCE editors. Some editors are advancing, and some are simple editors. I used the jquery validation plugin for client side validation. I am checking out one TinyMCE editor by adding the following code.

$('#submit').click(function() {

    var content = tinyMCE.activeEditor.getContent(); // get the content

    $('#description').val(content); // put it in the textarea

});

But now I have to check all the editors, any idea?

+3
source share
5 answers

Try

$('#submit').click(function() {

  for (i=0; i < tinymce.editors.length; i++){
    var content = tinymce.editors[i].getContent(); // get the content

    $('#description').val(content); // put it in the textarea
  }
});

or easier

$('#submit').click(function() {
     tinymce.triggerSave();
});
+10
source

A more general approach is to save the contents of the editor back to the text box, and then allow the jquery to check the magic in the text area itself

tinymce.init({
    setup: function (editor) {
        editor.on('init change', function () {
            editor.save();
        });
    }
});

Since the tinymce text box is hidden, you also need to update your jquery validation code something like this:

$('#myform').validate({
    ignore: ':hidden:not(textarea)'
});
+1

TinyMCE isDirty()

:

tinyMCE.activeEditor.isDirty()

,

0

java script code

 jQuery(document).ready(function(){
            // binds form submission and fields to the validation engine
            jQuery("#formID").validationEngine();
        });

HTML

TinyMCE

 <textarea rows="" cols="" id="first" class="validate[required] text-input tinymce"></textarea>

TinyMCE

<textarea rows="" cols="" id="second" class="validate[required] text-input tinymce"></textarea>

,

0

f Html editor tinymce, , , tinymce Htmleditor, , , .

tinymce.cshtml ok

  [Required(ErrorMessage = "Please enter About Company")]
  [Display(Name = "About Company : ")]
  [UIHint("tinymce_jquery_full"), AllowHtml]
  public string txtAboutCompany { get; set; }

  [Required(ErrorMessage = "Please enter About Company")]
  [Display(Name = "About Company : ")]
  [UIHint("tinymce_jquery_full"), AllowHtml]
  public string txtAboutCompany { get; set; }

,

 <div class="divclass">
     @Html.LabelFor(model => model.txtAboutCompany, new { @class = "required" })
     @Html.EditorFor(model => model.txtAboutCompany)
     <span class="field-validation-error" id="AC" style="margin:9px 0 0 157px;"></span>
 </div>
<div class="divclass">
     @Html.LabelFor(model => model.txtAboutCompany, new { @class = "required" })
     @Html.EditorFor(model => model.txtAboutCompany)
     <span class="field-validation-error" id="AC" style="margin:9px 0 0 157px;"></span>
 </div>

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();
    }
});

, .

0

All Articles