loveorigami / yii2-modal-ajax

A wrapper around Yii2 Bootstrap Modal for using an ActiveForm via AJAX inside.
MIT License
50 stars 30 forks source link

Multiple modal forms - select2 problem #28

Open stovesy opened 5 years ago

stovesy commented 5 years ago

I have registered two modal forms and was getting problems with missing select2 dropdowns. When the last for is rendered by ajax, only the first occurence of the select2 control was baing setup by javascript. Clearing the innerhtml when the modal closes solves this problem.

Alter kb-modal-ajax.js

    ModalAjax.prototype.init = function (options) {
        this.selector = options.selector || null;
        this.initalRequestUrl = options.url;
        this.ajaxSubmit = options.ajaxSubmit;
        jQuery(this.element).on('show.bs.modal', this.shown.bind(this));
        jQuery(this.element).on('hidden.bs.modal', this.closed.bind(this));
    };

    /**
     * Clear inner html when the form closes. This fixes a problem where items with the same id are not
     * rendered or have the correct javascript attached.
     */
    ModalAjax.prototype.closed = function (event){
        jQuery(this.element).find('.modal-body').html('<div class="modal-ajax-loader"></div>');
    }
loveorigami commented 5 years ago

In my case it is not worked. I have 2 nested modal ajax.

2019-11-18_17-03-44

After closed country modal - region modal is not loaded.

Result 2019-11-18_17-08-03