2
votes

I want to get the selected values in the multiple select input field on edit.

I am using select2 version:4

  • I am having a product form which is having a field called "condition" which is using select2 multi select option.
  • its working fine for now. i am adding these data to database as well.
  • but when i want to edit the same product i waant to show the previously selected conditions items which are in database.

How can i achieve this in select2.

Please send me the link which helps me to do this.

1
just retrieve the data which were stored in the database and add it to select option. Or am I missing something? - Abhishek Anand
how can this be duplicate of the question link by @Pedram . Its totally different - RoshJ

1 Answers

1
votes

Try this one (Select2 V.4)

 <select id="example" multiple="multiple" style="width: 300px">
    <option value="JAN">January</option>
    <option value="FEB">February</option>
    <option value="MAR">March</option>
    <option value="APR">April</option>
    <option value="MAY">May</option>
    <option value="JUN">June</option>
    <option value="JUL">July</option>
    <option value="AUG">August</option>
    <option value="SEP">September</option>
    <option value="OCT">October</option>
    <option value="NOV">November</option>
    <option value="DEC">December</option>
</select>

<script>
  $('#example').select2({
      placeholder: 'Select a month'
  });

  $(function(){
    $("#example").select2().val(["FEB","JUN"]).trigger('change.select2');
  });
</script>