<commit_before><input type="text" size="10" name="{{ name }}" value="{{ input_value }}" {{ extra_args }} />

{%- deferJS %}
<script type="text/javascript">
 function initWidget($) {
   var init_params = {
     minimumInputLength: 2,
     containerCssClass: 'form-control',
     {%- if not required %}allowClear: true,{%- endif %}
     placeholder: '',
     multiple: {{ s2_params.multiple |tojson }},
     {%- if values %}
     initSelection : function (element, callback) {
       var data = [{% for oid, label in values %}
                   {id: {{ oid|tojson }}, text: {{ label|tojson }}}{% if not loop.last %},{%- endif %}{% endfor %}
       ];
       if (data.length > 1) { /* debugger; */ } 
       else if (data.length > 0) {
         callback(data{%- if not s2_params.multiple %}[0]{%- endif %});
       }
     },
     {%- endif %}
     {%- if s2_params.format_result %}formatResult: {{ s2_params.format_result }},{%- endif %}
     ajax: {
       url: "{{ url }}",
       dataType: 'json',
       quietMillis: 100,
       data: function (term, page) {
         return { q: term };
       },
       results: function (data, page) {
         return {results: data.results, more: false};
       }
     }
   };

  $('input[name="{{ id }}"]').data({'init-with': 'select2',
                                    'init-params': init_params}
  );
 }

 require(['Abilian', 'jquery'],
         function(Abilian, $) {
             console.log('register onAppInit');
             Abilian.fn.onAppInit(function() { initWidget($); });
         });<commit_msg>fix display select2 values when >1<commit_after><input type="text" size="10" name="{{ name }}" value="{{ input_value }}" {{ extra_args }} />

{%- deferJS %}
<script type="text/javascript">
 function initWidget($) {
   var init_params = {
     minimumInputLength: 2,
     containerCssClass: 'form-control',
     {%- if not required %}allowClear: true,{%- endif %}
     placeholder: '',
     multiple: {{ s2_params.multiple |tojson }},
     {%- if values %}
     initSelection : function (element, callback) {
       var data = [{% for oid, label in values %}
                   {id: {{ oid|tojson }}, text: {{ label|tojson }}}{% if not loop.last %},{%- endif %}{% endfor %}
       ];
       if (data.length > 1) { /* debugger; */ } 
       if (data.length > 0) {
         callback(data{%- if not s2_params.multiple %}[0]{%- endif %});
       }
     },
     {%- endif %}
     {%- if s2_params.format_result %}formatResult: {{ s2_params.format_result }},{%- endif %}
     ajax: {
       url: "{{ url }}",
       dataType: 'json',
       quietMillis: 100,
       data: function (term, page) {
         return { q: term };
       },
       results: function (data, page) {
         return {results: data.results, more: false};
       }
     }
   };

  $('input[name="{{ id }}"]').data({'init-with': 'select2',
                                    'init-params': init_params}
  );
 }

 require(['Abilian', 'jquery'],
         function(Abilian, $) {
             console.log('register onAppInit');
             Abilian.fn.onAppInit(function() { initWidget($); });
         });
{'fraction_non_alphanumeric': 0.19006410256410255, 'fraction_numerical': 0.009615384615384616, 'mean_word_length': 2.194472876151484, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2971005', 'n_tokens_mistral': 1031, 'n_tokens_neox': 952, 'n_words': 218}