Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
37
rated 0 times [  39] [ 2]  / answers: 1 / hits: 26243  / 7 Years ago, tue, february 7, 2017, 12:00:00

I am using MVC5 to build a form with summernote editor.



Razor code:



<div class=form-group>
@Html.LabelFor(model => model.Content, htmlAttributes: new { @class = control-label })
@Html.EditorFor(model => model.Content, new { htmlAttributes = new { @class = form-control post-content} })
@Html.ValidationMessageFor(model => model.Content, , new { @class = text-danger })
</div>


JS:



$('#blog-form .post-content').summernote({
height: 400,
minHeight: 300,
codemirror: {
theme: 'default'
}
});


With the above setup the editor control renders fine. However, as soon as I move away from the editor, i.e. onBlur, I get the following error in the console:



Uncaught TypeError: Cannot read property 'replace' of undefined
at $.validator.escapeCssMeta (jquery.validate.js:1014)
at $.validator.errorsFor (jquery.validate.js:995)
at $.validator.prepareElement (jquery.validate.js:679)
at $.validator.element (jquery.validate.js:466)
at $.validator.onfocusout (jquery.validate.js:289)
at HTMLDivElement.delegate (jquery.validate.js:411)
at HTMLFormElement.dispatch (jquery-2.2.3.js:4737)
at HTMLFormElement.elemData.handle (jquery-2.2.3.js:4549)
at Object.trigger (jquery-2.2.3.js:7819)
at Object.simulate (jquery-2.2.3.js:7890)


Here is the rendered part of the DOM:



    <div class=form-group>
<label class=control-label for=Content>Content</label>
<textarea class=form-control post-content text-box multi-line id=Content name=Content style=display: none;></textarea>

<div class=note-editor note-frame panel panel-default>
...summernote generated...
</div>

<span class=field-validation-valid text-danger data-valmsg-for=Content data-valmsg-replace=true></span>
</div>


jQuery version: 2.2.3



jQuery Validate version: 1.16.0



Microsoft.jQuery.Unobtrusive.Validation version: 3.2.3



I have done some research and already know that this is not related to summernote plug-in. I tried running the following code inside and of outside document ready, but it did not work:



$.validator.setDefaults({
ignore: :hidden:not(.post-content)
});


Any ideas?


More From » jquery

 Answers
97

I use this script to tell the validator to ignore Summernote elements. It can be tweaked to ignore elements generated by other HTML editors.



$('form').each(function () {
if ($(this).data('validator'))
$(this).data('validator').settings.ignore = .note-editor *;
});

[#59046] Saturday, February 4, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
brittanye

Total Points: 263
Total Questions: 94
Total Answers: 115

Location: Burkina Faso
Member since Thu, Dec 23, 2021
3 Years ago
brittanye questions
Mon, Aug 10, 20, 00:00, 4 Years ago
Tue, Jun 16, 20, 00:00, 4 Years ago
Wed, Apr 22, 20, 00:00, 4 Years ago
Mon, Apr 13, 20, 00:00, 4 Years ago
;