Closed brendanmcoffey closed 13 years ago
sounds like a bug with tinymce
This also happens to ckeditor and punymce going to try YUI 2 Rich Text Editor tomorrow, so this looks more like a problem with bootstrap
I found the beginnings of a workaround for this problem with TinyMCE. If you bind a new instance of TinyMCE to the modal "shown" event, then it seems to work reasonably well. The one problem with this is that if you open a modal, close it, and open it again, the TinyMCE instance doesn't work
Here's my code (to be placed before the closing body tag):
$('.the-modal').bind('shown', function() {
$('textarea.tinymce-modal').tinymce({
// TinyMCE Options
});
});
EDIT If you have just one modal, then adding this code as well will solve the issue. If you have multiple modals, then you can't close one and open another with TinyMCE still working:
$('.the-modal').bind('hidden', function() {
$('textarea.tinymce-modal').tinymce().remove();
});
I tried using .destroy();
but that seems to interrupt the javascript for the modal itself
have you tried bringing it up with the the tinyMCE authors? Did they have any suggestions?
I have to confess I only came across this post via a quick Google, so I haven't been looking too hard! Also, it appears TinyMCE only provide support for paid licenses. Nevertheless, I have found this discussion on the TinyMCE forums: http://www.tinymce.com/forum/viewtopic.php?id=26541
I'm now having a play with Firebug and seeing if I can find a better workaround using tinyMCE.execCommand('mceAddControl', false, 'mce');
which may involve using the same ID more than once in some truly hideous code! I'm slightly concerned that .destroy()
affects the modal itself, although that might be just how jQuery works.
Most of this seems to be a TinyMCE thing, although I can't vouch for the issues with ckeditor and punymce which may need looking into
Right: a relatively complete workaround.
You need to apply TinyMCE to the textarea after the modal has appeared, and then remove it if the modal is hidden. You don't have to necessarily initialise TinyMCE all over again, but you do have to make sure it's applied to the textarea. If you have multiple modals and textareas, they all have to have separated IDs In my case, I'm putting the below code after each modal (fortunately in a PHP loop, note the PHP shorthand of <?=$reply["id"]?>
)
<script type="text/javascript">
$('.the-modal').bind('shown', function() {
tinyMCE.execCommand('mceAddControl', false, 'mce-<?=$reply["id"]?>');
});
$('.the-modal').bind('hide', function() {
tinyMCE.execCommand('mceRemoveControl', false, 'mce-<?=$reply["id"]?>');
});
</script>
I have no idea what sort of an impact this will have on performance on a fully-fledged site as I'm only testing this on localhost, but it seems to work.
works nice thanks
Yes, just got it working myself. Thanks BobLoco!
Here's a workaround for TinyMCE v4.3.11 and Bootstrap v3.3.5:
Found here.
Hi @icamys!
You appear to have posted a live example (http://fiddle.jshell.net/e99xf/13/show/light/), which is always a good first step. However, according to Bootlint, your example has some Bootstrap usage errors, which might potentially be causing your issue:
.modal-header
must be a child of .modal-content
.modal-body
must be a child of .modal-content
.modal-footer
must be a child of .modal-content
.hide
should not be used on .modal
in Bootstrap v3.<button>
s missing a type
attribute.You'll need to fix these errors and post a revised example before we can proceed further. Thanks!
(Please note that this is a fully automated comment.)
@icamys Thanks for your solution. It was a perfect fix for me.
@icamys Your or any of the above solutions work only for the static content, means if the form that you are opening in the Modal window is in the same page/view but if you try to load the content from a url with a custom anchor like
<a id="modalUpdateButton" class="grid-action modalButton" value="/post/modal" href="/post/modal.php" title="Updating Ticket: "><span class="glyphicon glyphicon-pencil"></span></a>
and bind the modal with this button using
$('.modalButton').on('click',function (e) {
$('#modal').modal('show')
.find('#modalContent')
.load($(this).attr('value'));
e.preventDefault();
});
with the following default HTML
<div id="modal" class="fade modal" role="dialog" tabindex="-1">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div id="modalHeader" class="modal-header">
<button type="button" id="close-button" class="btn btn-warning pull-right modalClose" data-dismiss="modal" aria-hidden="true">Close</button>
<span id="modalHeaderTitle"></span>
</div>
<div class="modal-body">
<div id="message"></div><div id="modalContent"></div>
</div>
</div>
</div>
</div>
It does not work where ever you try to load the focusin
from the main page or the view from where the form is loaded
Works great. Been searching for hours. Thank you icamys!
@icamys Thank you!! I have been playing with this for days using Bootstarp 4 with TinyMCE 5.
Actually everything was working except the link dialog (I could not click in any of the fields). Once I came across your solution it took a little digging but I found I needed to use the .tox-dialog instead of .mce-window (which is the pop div TinyMCE 5 is using).
$(document).on('focusin', function(e) {
if ($(e.target).closest(" .tox-dialog").length) {
e.stopImmediatePropagation();
}
});
There own documentation says to use .mce-window but that made no difference for my implementation so I'm wondering if this is just a case of old documentation based on TinyMCE 4: https://www.tiny.cloud/docs/integrations/bootstrap
Who use materializeCss, can use the solution below.
$.extend(M.Modal.prototype, {
_handleFocus(e) {
if (!this.el.contains(e.target)
&& this._nthModalOpened === M.Modal._modalsOpen
&& document.defaultView.getComputedStyle(e.target, null).zIndex < 1002) {
this.el.focus();
}
}
});
Fix by @sigma-technology, https://github.com/Dogfalo/materialize/issues/5972
If someone is facing similar issue in react-bootstrap, you can fix this issue by passing enforceFocus={false}
prop to the <Modal>
component.
If someone is facing similar issue in Ant Design, you can fix this issue by passing forceRender={true}
prop to the
$.extend(M.Modal.prototype, { _handleFocus(e) { if (!this.el.contains(e.target) && this._nthModalOpened === M.Modal._modalsOpen && document.defaultView.getComputedStyle(e.target, null).zIndex < 1002) { this.el.focus(); } } });
Thank you so much! This worked for me.
Loading a TinyMCE WSIWYG field and then popping it up in the modal causes the text field to become uneditable. The text that should be inside the