CKEditor链接输入不适用于模式 [英] CKEditor Link input not working in modal

查看:119
本文介绍了CKEditor链接输入不适用于模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,其中使用了带有表单和ckeditor的模式,而Link输入不起作用.

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/

以及此示例的代码.

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.

谢谢:)

推荐答案

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

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

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

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

这篇关于CKEditor链接输入不适用于模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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