i use select2 plugin display searchable dropdown (with option select multiple items). can me form (re)submitted every time new value selected (and deselected, if possible).
i know select2 has "select" event, can't code working. form code:
<select class="form-control select2-search" name="product_id[]" multiple="multiple"><option value='1'>1</option>...<option value='999'>999</option></select> here's code select2:
<script type="text/javascript"> $(document).ready(function() { var $eventselect=$(".select2-search").select2({ minimumresultsforsearch: 6 }); $eventselect.on("select2:select", function() { this.submit(); }); }); </script> what's wrong here?
you submiting select, not form..
try this
<script type="text/javascript"> $(document).ready(function() { var $eventselect=$(".select2-search").select2({ minimumresultsforsearch: 6 }); $eventselect.on("select2:select", function() { console.log("select2:select"); $(this).parents('form').submit(); }); }); </script> or try this
<script type="text/javascript"> $(document).ready(function() { var $eventselect=$(".select2-search").select2({ minimumresultsforsearch: 6 }); $eventselect.on("change", function() { console.log("select2:select"); $(this).parents('form').find('button').click(); }); }); </script>
Comments
Post a Comment