سؤال

I have a tinymce rich text editor on my aspx apge(.net), I want to apply client side validation on this. Can anybody help me?

هل كانت مفيدة؟

المحلول

You have to use tinyMCE.get('<%=txt_editor1.ClientID %>').getContent() instead of document.getElementById('<%=txt_editor1.ClientID %>').value so you could achieve like this.

function valid(){
  var content = tinyMCE.get('<%=txt_editor1.ClientID %>').getContent();
  if(content.length>100){
  return false;
  }
  return true;


}

نصائح أخرى

if you have Html editor tinymce the required validation is not working ok, you can use this code to solve your problem,
install tinymce in your application

In model give the path of tinymce.cshtml page ok

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

Now in your view add one span like this

 <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>

Create jQuery on submit button click event

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

i hope your problem may be solve

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top