V
V
VanilaSpirit2020-10-16 16:20:42
JavaScript
VanilaSpirit, 2020-10-16 16:20:42

Why Uncaught TypeError: Cannot read property 'Constructor' of undefined?

There is a modal on the page that opens a form with two textarea:

<div class="modal box-modal">
<form class="">
    <div class="form_row">
        <div class="input_cover">
            <textarea class="ckeditor" rows="10" cols="80" name="editor1" id="editor1"></textarea>
        </div>
    </div>
    <div class="form_row">
        <div class="input_cover">
            <textarea class="ckeditor" rows="10" cols="80" name="editor2" id="editor2"></textarea>
        </div>
    </div>
    <button class="save">Сохранить</button>
</form>
</div>


There was a problem that it opened with two editors, but they could not be edited.
There are a lot of people on the Internet who solved the problem, let's go with the code:
<script>
    $(document).ready(function () {
        $.fn.modal.Constructor.prototype.enforceFocus = function () {
            modal_this = this;
            $(document).on('focusin.modal',
                function(e) {
                    if (modal_this.$element[0] !== e.target &&
                        !modal_this.$element.has(e.target).length
                        // add whatever conditions you need here:
                        &&
                        !$(e.target.parentNode).hasClass('cke_dialog_ui_input_select') &&
                        !$(e.target.parentNode).hasClass('cke_dialog_ui_input_text')) {
                        modal_this.$element.focus();
                    }
                });
        };
});
</script>


But when loading the modal, they are still not available, and an error from the topic topic also appears.

It's funny that I inserted the same code into fiddle and other analogues - everything worked ...

What could be wrong?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question