pat*_*cia 2 html jquery modal-dialog ckeditor djangocms-text-ckeditor
我有一个项目,在该项目中我使用带有表单和 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">×</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>
Run Code Online (Sandbox Code Playgroud)
JS:
CKEDITOR.disableAutoInline = true;
$(document).ready(function() {
$('#myModal').on('shown.bs.modal', function () {
CKEDITOR.inline('myModalLabel');
CKEDITOR.inline('bodyModal');
})
});
Run Code Online (Sandbox Code Playgroud)
这不完全是我的代码,但错误是相同的。如果您单击模态,然后尝试添加链接,则无法在输入字段中写入 url。
谢谢 :)
Che*_*enL 11
互联网上的很多答案都提出了多种修复方法,这对我有用,对于 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();
}
});
};
Run Code Online (Sandbox Code Playgroud)
如果您在引导程序 3 上运行,则覆盖$.fn.modal.Constructor.prototype.enforceFocusinsdead。
小智 7
要解决这个问题只需做以下几件事:
在 body 标签上添加自定义 CSS 规则
body {
--ck-z-default: 100;
--ck-z-modal: calc( var(--ck-z-default) + 999 );
}
将模态选项焦点值设置为 false
$( '#basicModal' ).modal( {
focus: false
} );
<div class="modal fade " data-focus="false" id="basicModal">| 归档时间: |
|
| 查看次数: |
3455 次 |
| 最近记录: |