使用 CKEditor 很新,我对收到的这个 jQuery 验证错误感到困惑。我的项目是 C# MVC 并使用 UnobtrusiveJavascript 和 Unobtrusive Validate 插件。
我有一个通过 HtmlHelper 构建的文本区域:
@Html.TextAreaFor(model => model.BookSummary, new { id = "bookMainInfo" })
这是我正在做的创建编辑器。打开页面时它会替换文本区域:
var theEditor;
// Load CKEditor in place of the information table
ClassicEditor
.create(document.querySelector('#bookMainInfo'), {
toolbar: ['heading', 'bold', 'italic', 'underline', 'link', 'bulletedList', 'numberedList', 'blockQuote', 'undo', 'redo'],
heading: {
options: [
{ model: 'paragraph', title: 'Paragraph', class: 'ck-heading_paragraph' },
{ model: 'heading4', view: 'h4', title: 'Large Heading', class: 'ck-heading_heading4' },
{ model: 'heading5', view: 'h5', title: 'Medium Heading', class: 'ck-heading_heading5' },
{ model: 'heading6', view: 'h6', title: 'Small Heading', class: 'ck-heading_heading6' }
]
}
})
.then(editor => {
theEditor = editor; // Save editor for usage later
})
.catch(error => {
console.error(error);
});
一切似乎都正常。我可以成功输入数据并毫无问题地提交表单。但是,如果我在编辑器中输入了任何文本并在编辑器外部单击,则会在控制台中引发以下错误:
VM149 jquery.validate.js:1033 Uncaught TypeError: Cannot read property 'replace' of undefined
at $.validator.escapeCssMeta (VM149 jquery.validate.js:1033)
at $.validator.errorsFor (VM149 jquery.validate.js:1014)
at $.validator.prepareElement (VM149 jquery.validate.js:692)
at $.validator.element (VM149 jquery.validate.js:475)
at $.validator.onfocusout (VM149 jquery.validate.js:300)
at HTMLDivElement.delegate (VM149 jquery.validate.js:424)
at HTMLFormElement.dispatch (VM148 jquery-3.3.1.js:5183)
at HTMLFormElement.elemData.handle (VM148 jquery-3.3.1.js:4991)
at Object.trigger (VM148 jquery-3.3.1.js:8249)
at Object.simulate (VM148 jquery-3.3.1.js:8318)
错误被记录了两次,我可以通过点击进入和退出带有文本的编辑器来重复生成错误。空的编辑器不会导致错误。似乎它在 jquery.validate.js 的这一部分具体爆炸了:
escapeCssMeta: function( string ) {
return string.replace( /([\\!"#$%&'()*+,./:;<=>?@\[\]^`{|}~])/g, "\\$1" );
}
我能做些什么来抑制这个错误或阻止 jQuery 验证做它试图在这里做的任何事情吗?它在功能上对我没有影响,但它很烦人。