function apply_select2(el, canDefer) {
        // Convert element to jQuery object (if it isn't already)
        var $el = $(el),
            thisTagField = this,

            // Get info from element
            isSingle = $el.data('tag-type') === "single",
            options = $el.data('tag-options') || {},
            settings = options.autocomplete_settings || {},
            list = $el.data('tag-list'),
            url = $el.data('tag-url'),

            // Other values
            $blank, args, field_args
        ;

        // See if this is a deferred tag
        if (canDefer && settings.defer) {
            return $el;
        }
        delete settings.defer;

        // Clear out first option if it's Django's blank value
        $blank = $el
            .find('option:first[value=""]:contains("---------")')
            .text('')
        ;

        // Default constructor args, which can be overridden
        args = {
            width: 'resolve'
        };

        // Merge in any overrides
        field_args = settings;
        if (field_args) {
            $.extend(args, field_args);
        }

        // Merge in common compulsory settings
        $.extend(args, {
            // Our overriden methods
            tokenizer: tokenizer,
            createSearchChoice: createSearchChoice,

            // Things defined by field/tag options, which can't be overridden
            multiple: !isSingle,
            quotedTags: true,
            allowClear: !options.required,
            maximumSelectionSize: isSingle ? 1 : options.max_count || 0,
            spaceDelimiter: options.space_delimiter !== false
        });

        // Add in any specific to the field type
        if (isSingle) {
            args['initSelection'] = initSelectionSingle;
        } else {
            args['initSelection'] = initSelectionMulti_factory(args);
        }
        if (url) {
            args['ajax'] = {
                url: url,
                dataType: 'json',
                data: function (term, page) {
                    return {q:term, p:page};
                },
                results: function (data) {
                    data['results'] = listToData(data['results']);
                    return data;
                }
            };

            // Merge in override ajax values
            if (field_args && field_args.ajax) {
                $.extend(args['ajax'], field_args.ajax);
            }

        } else if (isSingle) {
            // Make SingleTagField look like a select, set data not tags
            args['data'] = listToData(list);

        } else {
            // Multiple tags, normal tags mode appropriate
            args['tags'] = list || [];
        }

        // Initialise
        return $el.select2(args);
    }
/** Apply select2 to a specified element

        Arguments:
            el          The DOM or jQuery object to use as the tag element
            canDefer    If true and tag-options.defer is set, this field
                        will not be initialised.
    */
Apply select2 to a specified element
Arguments:
el          The DOM or jQuery object to use as the tag element
canDefer    If true and tag-options.defer is set, this field
will not be initialised.
Apply select2 to a specified element Arguments : el The DOM or jQuery object to use as the tag element canDefer If true and tag - options . defer is set this field will not be initialised .
function apply_select2(el, canDefer) {
        var $el = $(el),
            thisTagField = this,
            isSingle = $el.data('tag-type') === "single",
            options = $el.data('tag-options') || {},
            settings = options.autocomplete_settings || {},
            list = $el.data('tag-list'),
            url = $el.data('tag-url'),
            $blank, args, field_args
        ;
        if (canDefer && settings.defer) {
            return $el;
        }
        delete settings.defer;
        $blank = $el
            .find('option:first[value=""]:contains("---------")')
            .text('')
        ;
        args = {
            width: 'resolve'
        };
        field_args = settings;
        if (field_args) {
            $.extend(args, field_args);
        }
        $.extend(args, {
            tokenizer: tokenizer,
            createSearchChoice: createSearchChoice,
            multiple: !isSingle,
            quotedTags: true,
            allowClear: !options.required,
            maximumSelectionSize: isSingle ? 1 : options.max_count || 0,
            spaceDelimiter: options.space_delimiter !== false
        });
        if (isSingle) {
            args['initSelection'] = initSelectionSingle;
        } else {
            args['initSelection'] = initSelectionMulti_factory(args);
        }
        if (url) {
            args['ajax'] = {
                url: url,
                dataType: 'json',
                data: function (term, page) {
                    return {q:term, p:page};
                },
                results: function (data) {
                    data['results'] = listToData(data['results']);
                    return data;
                }
            };
            if (field_args && field_args.ajax) {
                $.extend(args['ajax'], field_args.ajax);
            }
        } else if (isSingle) {
            args['data'] = listToData(list);
        } else {
            args['tags'] = list || [];
        }
        return $el.select2(args);
    }
function apply_select2 ( el , canDefer ) { var $el = $ ( el ) , thisTagField = this , isSingle = $el . data ( 'tag-type' ) === "single" , options = $el . data ( 'tag-options' ) || { } , settings = options . autocomplete_settings || { } , list = $el . data ( 'tag-list' ) , url = $el . data ( 'tag-url' ) , $blank , args , field_args ; if ( canDefer && settings . defer ) { return $el ; } delete settings . defer ; $blank = $el . find ( 'option:first[value=""]:contains("---------")' ) . text ( '' ) ; args = { width : 'resolve' } ; field_args = settings ; if ( field_args ) { $ . extend ( args , field_args ) ; } $ . extend ( args , { tokenizer : tokenizer , createSearchChoice : createSearchChoice , multiple : ! isSingle , quotedTags : true , allowClear : ! options . required , maximumSelectionSize : isSingle ? 1 : options . max_count || 0 , spaceDelimiter : options . space_delimiter !== false } ) ; if ( isSingle ) { args [ 'initSelection' ] = initSelectionSingle ; } else { args [ 'initSelection' ] = initSelectionMulti_factory ( args ) ; } if ( url ) { args [ 'ajax' ] = { url : url , dataType : 'json' , data : function ( term , page ) { return { q : term , p : page } ; } , results : function ( data ) { data [ 'results' ] = listToData ( data [ 'results' ] ) ; return data ; } } ; if ( field_args && field_args . ajax ) { $ . extend ( args [ 'ajax' ] , field_args . ajax ) ; } } else if ( isSingle ) { args [ 'data' ] = listToData ( list ) ; } else { args [ 'tags' ] = list || [ ] ; } return $el . select2 ( args ) ; }
Apply select2 to a specified element
Arguments:
el          The DOM or jQuery object to use as the tag element
canDefer    If true and tag-options.defer is set, this field
will not be initialised.
Apply select2 to a specified element Arguments : el The DOM or jQuery object to use as the tag element canDefer If true and tag - options . defer is set this field will not be initialised .
// Convert element to jQuery object (if it isn't already) // Get info from element // Other values // See if this is a deferred tag // Clear out first option if it's Django's blank value // Default constructor args, which can be overridden // Merge in any overrides // Merge in common compulsory settings // Our overriden methods // Things defined by field/tag options, which can't be overridden // Add in any specific to the field type // Merge in override ajax values // Make SingleTagField look like a select, set data not tags // Multiple tags, normal tags mode appropriate // Initialise