javascript - Select2 strips all attributes from <option> -


i'm using select2 on select tag, there additional when user changes selected option. , makes use of attributes set data-price instance. select2 seems striping attributes <option> tags except value.

how can disable behavior or how can data values other way?

edit: forgot add i'm using sonata admin. sonata 1 loading select2 default.

select2 seems striping attributes tags except value

not true data-* attributes still there have them :

$("#singleselectexample").select2();  $('body').on('change', '#singleselectexample', function(){     console.log( $('#singleselectexample option:selected').data('price') ); }) 

hope helps.

$("#singleselectexample").select2();    $('body').on('change', '#singleselectexample', function(){    console.log( $('#singleselectexample option:selected').data('price') );  })
.selectrow {    display : block;    padding : 20px;  }  .select2-container {    width: 200px;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <script src="https://select2.github.io/select2/select2-3.5.1/select2.js"></script>  <link href="https://select2.github.io/select2/select2-3.5.1/select2.css" rel="stylesheet"/>  <div class="selectrow">    <select id="singleselectexample">      <option></option>      <option value="1" data-price="111">option 1</option>      <option value="2" data-price="222">option 2</option>      <option value="3" data-price="333">option 3</option>    </select>  </div>


Comments