• jQuery Validate + Ckeditor 驗證 textarea 解決方式


    jQuery Validate + Ckeditor 驗證 textarea 解決方式

    html

    <textarea name="content" id="content" class="ckeditor" placeholder="請輸入內容" rows="24" cols="80"></textarea>
    

    class=ckeditor 會使用 DATA-API 模式自動初始化

    javascript

    $(document).ready(function(){
        //bind submit to update textarea from ckeditor 
        $('#form').submit(function(){
            $('textarea.ckeditor').each(function () {
               var $textarea = $(this);
               $textarea.val(CKEDITOR.instances[$textarea.attr('name')].getData());
            });
        });
    
        //validate
        $('#form').validate({
            rules: {
                content: {
                    required: true
                }
            },
            ignore: '',
            errorPlacement: function(error, element) {
                if (element.attr('name') == 'content') {
                    error.insertAfter($(element).parent().children().last());
                } else {
                    error.insertAfter(element);
                }
            }
        });
    });
    

    form submit 必須要放在 validate 之前宣告

    在 jquery validate 的 rules 裡面將 ignore 設定成為空值

    並且在 form submit 的時候更新 ckeditor 的 instance

    最後再更改 jquery validate 的 errorPlacement 讓 label.error 可以顯示在正確的位置,之後即可解決這個問題。

    来自:http://oommgg.net/2011/11/jquery-validate-ckeditor-%E9%A9%97%E8%AD%89-textarea-%E8%A7%A3%E6%B1%BA%E6%96%B9%E5%BC%8F/

  • 相关阅读:
    在一个页面用Ajax访问另一个页面弹出询问框怎么办
    还有一张呢
    系统相关信息查看
    linux dd 命令使用说明
    Github 使用说明
    Hadoop HA 资料
    fedora 在virtualbox安装guest additions
    git 使用记录
    linux console 小技巧
    Agent admitted failure to sign using the key 错误及解决方法
  • 原文地址:https://www.cnblogs.com/mbtq/p/4514176.html
Copyright © 2020-2023  润新知