无法获取TinyMCE的使用jQuery不显眼的审定工作 [英] Unable to get TinyMCE working with jQuery Unobtrusive Validation

查看:178
本文介绍了无法获取TinyMCE的使用jQuery不显眼的审定工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个形式,就是用不显眼的审定,并预期所有我的领域的工作,但一旦我加入TinyMCE的(或任何其他所见即所得的编辑器),它使用被隐藏的,是$ P $被pventing领域的textarea包括在客户端验证。有没有一种方法,我可以钩到验证,包括这个隐藏字段,或者用不同的方式来隐藏textarea的,这样会将它之前的帖子后面验证?

I've got a form that's using unobtrusive validation and works as expected for all of my fields but once I added TinyMCE (or any other WYSIWYG editor) the textarea it uses gets hidden and is preventing the field from being included in client-side validation. Is there a way I could hook into the validation to include this hidden field, or maybe a different way to hide the textarea so it gets validated before the post back?

推荐答案

我有同样的问题,这个星期。结束了与此解决它:

I had the same issue this week. Ended up solving it with this:

// sync tinymce content to validate before submitting form
$('form input[type=submit]').click(function () {
    tinyMCE.triggerSave();
});

......我们还可以使用保存插件,但为了得到它来触发验证,只好把这个TinyMCE的编辑器模板:

...we also use the save plugin, but in order to get it to trigger validation, had to put this in the TinyMCE editor template:

function onSavePluginCallback(ed) {
    var form = $(ed.formElement);
    var isValid = form.valid();
    if (isValid) {
        form.submit();
    }
}

(function () {

    tinyMCE.init({
        ...
        save_onsavecallback: 'onSavePluginCallback',
        ...

更新

这是有一定道理的文字区域不被悄悄地验证,而它的隐藏。我忘了补充另一一段JavaScript代码,我不得不做这项工作:

That does make sense that the textarea isn't being unobtrusively validated while it's hidden. I forgot to add another piece of javascript I had to make this work:

$.validator.setDefaults({
    ignore: ''
});

在默认情况下,JQuery验证忽略不可见的领域。为忽略参数的默认值是':隐藏。通过将其设置为空字符串,你告诉JQuery验证不要忽略隐藏的投入。

By default, jquery validate ignores fields that are not visible. The default value for the ignore parameter is ':hidden'. By setting it to an empty string, you are telling jquery validate to not ignore hidden inputs.

这篇关于无法获取TinyMCE的使用jQuery不显眼的审定工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆