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