开发者

nicEdit and MVC 3/ jquery required field validation

I am using NicEdit as a wysiwig JS editor for a page in my MVC3 project. The field i want an editor for is a textarea and it is a 'required开发者_Go百科' field.

The problem is that the clientside JQuery validation does not 'see' the content entered in nicEdit textarea (because nicEdit completely changes the page and the textarea IS empty). How would i fix this? Is there a way to immmediately fill the textarea with the value of the edit box? Can I hook into the JQuery validation in a nice way so things stay 'unobtrusive'?

Thanks


OK here's what i've come up with. I just added some code to the click handler of the submit button so the nicEditor updates the html before jquery validation kicks in:

$('input[type=submit]').bind('click', function () {
    for(var i=0;i<nicEditor.nicInstances.length;i++){
        nicEditor.nicInstances[i].saveContent();
    }
});

Also as a note i had to remove some code from NicEdit.js as it was adding linebreak tags if the content was empty like this:

if(this.getContent() == "") {
  this.setContent('<br />');

}

I removed this code so a textarea stays empty.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜