TinyMCE client validation problem

后端 未结 2 904
一个人的身影
一个人的身影 2021-02-05 21:59

I have problem with TinyMCE editor. I have form with few text fields and textarea (tinymce), and enabled client validation. When I click save button validation occures on all te

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-05 22:46

    If you have same problem like Tinymce required validation is not fire on form submit time i have one solution like this, i know this is not proper way but it work fine see the below code install tynymce jquery package in your application

    THIS IS MODEL

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

    now in cshtml file means in our view

    @Html.LabelFor(model => model.txtAboutCompany, new { @class = "required" }) @Html.EditorFor(model => model.txtAboutCompany)

    and on submit button click event check this 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 this code,

提交回复
热议问题