【问题标题】:CKEditor Link input not working in modalCKEditor 链接输入在模式下不起作用
【发布时间】:2017-04-28 13:00:51
【问题描述】:

我有一个项目,我在其中使用带有表单和 ckeditor 的模式,但链接输入不起作用。

这是重现此问题的小提琴:

http://jsfiddle.net/8t882a2s/3/

还有这个例子的代码。

HTML:

        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                        <h4 class="modal-title" contenteditable="true" id="myModalLabel">Modal title</h4>
                    </div>
                    <div id="bodyModal" contenteditable="true" class="modal-body">
                        ...
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        <button type="button" class="btn btn-primary">Save changes</button>
                    </div>
                </div>
            </div>
        </div>

 <button type="button" class="btn btn-default navbar-btn  margin-right-button-nav" data-toggle="modal" data-target="#myModal"><span class="glyphicon glyphicon-new-window"></span> Edit Modal</button>

JS:

CKEDITOR.disableAutoInline = true;

$(document).ready(function() {
    $('#myModal').on('shown.bs.modal', function () {
        CKEDITOR.inline('myModalLabel');
        CKEDITOR.inline('bodyModal');
    })    
});

这不完全是我的代码,但错误是相同的。如果您单击模态框,然后尝试添加链接,则无法在输入字段中写入 url。

谢谢:)

【问题讨论】:

    标签: jquery html modal-dialog ckeditor djangocms-text-ckeditor


    【解决方案1】:

    互联网上的许多答案提出了多种修复方法, 这对我有用,对于 bootstrap 4 项目:

    $.fn.modal.Constructor.prototype._enforceFocus = function() {
                    var $modalElement = this.$element;
                    $(document).on('focusin.modal',function(e) {
                        if ($modalElement.length > 0 && $modalElement[0] !== e.target
                            && !$modalElement.has(e.target).length
                            && $(e.target).parentsUntil('*[role="dialog"]').length === 0) {
                            $modalElement.focus();
                        }
                    });
                };
    

    如果您在引导程序 3 上运行,则覆盖 $.fn.modal.Constructor.prototype.enforceFocusinsdead。

    【讨论】:

    • 这应该被接受为答案...为我工作(引导 3)...谢谢!
    • 我同意,这应该是公认的答案。这解决了我在 Bootstrap 模态中使用两个单独的 HTML 编辑器和它们自己的对话框模态时遇到的相同问题!
    • 对我来说,空函数初始化成功了:$.fn.modal.Constructor.prototype._enforceFocus = function() {}
    • @ChenL 谢谢哥们,这在 bootstrap 4 中对我有用。
    • 同意 - 适用于 BS 4.5
    【解决方案2】:

    要解决这个问题,做以下事情就足够了:

    1. 在你的 body 标签上添加自定义 css 规则

      body { --ck-z-default: 100; --ck-z-modal: calc( var(--ck-z-default) + 999 ); }

    2. 将模态选项焦点值设置为 false

      • 如果您使用 javascript 来启动模态,您应该这样做:

      $( '#basicModal' ).modal( { focus: false } );

      • 如果你使用数据属性来启动模式,你应该像这样 &lt;div class="modal fade " data-focus="false" id="basicModal"&gt;

    【讨论】:

    • 在我的例子中,链接表单的弹出窗口隐藏在模式后面,你的 css 把它带回来了。谢谢
    【解决方案3】:

    没错!对我来说 data-focus="false" 解决了所有问题

    【讨论】:

      【解决方案4】:

      对我来说,从 modal 属性中删除 tabindex="-1" 可以解决问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-02-15
        • 2017-01-07
        • 2019-01-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多