Select2 – style maintenance

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #10045304
    ubi1k
    Participant

    Hi,
    I have this situation.
    If I apply select2 via code to a select, the style from your “form-control” and “form-control-modern” classes is lost.
    How can I keep the style?


    #10045307
    Support
    Keymaster

    Hello, to initialize the select2 you need to run this code:

    // Select2
    (function($) {
    
    	'use strict';
    
    	if ( $.isFunction($.fn[ 'select2' ]) ) {
    
    		$(function() {
    			$('[data-plugin-selectTwo]').each(function() {
    				var $this = $( this ),
    					opts = {};
    
    				var pluginOptions = $this.data('plugin-options');
    				if (pluginOptions)
    					opts = pluginOptions;
    
    				$this.themePluginSelect2(opts);
    			});
    		});
    
    	}
    
    }).apply(this, [jQuery]);

    Make sure the HTML has all the attributes as our examples.

    Kind Regards.


    #10045309
    ubi1k
    Participant

    OK, and what can I do for dynamically created selects?


    #10045310
    Support
    Keymaster

    Hi, you just need to run that function after you create that new select, it will apply the function/style.

    Similar topic: https://www.okler.net/forums/topic/multi-select-how-to-setassign-values-dynamically-using-ajax/


    #10045311
    ubi1k
    Participant
    This reply has been marked as private.
    #10045312
    ubi1k
    Participant
    This reply has been marked as private.
    #10045313
    Support
    Keymaster

    Hello, I tested the HTML you provided and add it dinamically and ran the JS and this was the result:

    Tested on original forms-advanced.html file.

    So it’s probably related to CSS conflict, can you send me the URL of your site so I can check it for you?

    Thanks.


Viewing 7 posts - 1 through 7 (of 7 total)

This topic is marked as "RESOLVED" and can not rceive new replies.