CKEditor Link input not working in modal

ⅰ亾dé卋堺 提交于 2019-12-11 06:17:39

问题


I've got a project in which I use a modal with a form and a ckeditor and the Link input doesn't work.

Here's a fiddle that recreates this problem:

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

And the code of this example.

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');
    })    
});

This isn't exactly my code but the bug is the same. If you click in the modal and then try do add a Link you can't write the url in the input field.

Thanks :)


回答1:


lots of answers around the internet suggested multiple ways for fixes, this worked for me, for a bootstrap 4 project:

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

if your running on bootstrap 3, then override $.fn.modal.Constructor.prototype.enforceFocus insdead.




回答2:


To solve this issue is enough to do the following things:

  1. Add custom css rules on your body tag

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

  2. Set your modal options focus value to false

    • if you are using javascript to launch modal you should do it like this:

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

    • if you are using data attributes to launch modal you should have it like this <div class="modal fade " data-focus="false" id="basicModal">


来源:https://stackoverflow.com/questions/41121577/ckeditor-link-input-not-working-in-modal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!