Question

I am using a html editor in my page and it is a required field which need to be validated on the button click even though i did not enter any text it is not firing on the button click can anyone help me out?

thanks in advance :)

Was it helpful?

Solution

You can Do it through Jquery . Just change the type of your button from'Submit' to 'button'

and use the below code

$(document).ready(function(){
    $('#YourButtonID').click(function(){
          var EditorText=$('#YourEditorID').text();
          if(EditorText!='')
          {
              //Perform Your Actions
          }
          else
          {
            // Write any user interactive validation message
            alert('Kindly fill in some text in the editor');
          }
     })
 })

Hope This Helps You

OTHER TIPS

code would help but if say for instance you're using "TinyMCE" I know that will validate with unobtrusive validation without any issues.

So, in your class you might have something like:

[Required]
public String myHTMLField { get; set; }

..amongst other fields...

then in your view (which uses the above class) you would include the jquery validation and unobtrusive validation in there and on the form field have something like

@Html.TextArea(m=>m.myHTMLField, Model.myHTMLField, new { @class="tiny-mce" })
@Html.ValidateMessageFor(m=>m.myHTMLField)

..where class="tiny-mce" is the trigger for applying the HTML Editor, and the unobtrusive validation will do the rest!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top