select2 id property in Select2 4.0.3

36 views
Skip to first unread message

Jean-Claude Dauphin

unread,
Jun 26, 2017, 4:01:12 PM6/26/17
to select2
In release 3.4.6, I was able to change the id that is set in the <input type="hidden" /> tag as follow

$("#query").select2({
               minimumInputLength: 2,           
               allowClear: true,
               multiple: true,
               separator: "%",

               // Function to submit the value (text:) from the selection
               //  instead of the selected object's ID
               id: function(object) {
                   // return only the term without the field and occurences
                   // number
                  
                   return object.text.split("\t", 2)[1];
                  },
                  ........  

I have kept this code when updating to 4.0.3 but the <select> name send the id and not the text

I would appreciate any suggestions on changing the value assoiciated with the select name

I have something like this

 <form method="POST" action="doSearchGoogle.action" class="well form-search">
<!--    <form action="jsp/search/displayResults.jsp"  onsubmit="doSearchGoogle()" class="form-search">-->
      
          <div class="input-append">
             <select type="hidden" id="query" name="googleQuery" style="width:500px" class="span2 search-query">
             <select>
             <button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-search"></span>Search</button>
          </div>

   </form>

Thank you in advance

Best wishes,

JC

Reply all
Reply to author
Forward
0 new messages