jquery - Bootstrap-Select doesn't respond to dynamically added rows/content -


i have table row multiple select boxes on form input.

i can clone row create new row. this.

var counter = 1; $(document).ready(function() {     $('#additemrow').click(function() {           $('#itemmultiinputtable tr:last').clone(true,true).insertafter('#itemmultiinputtable tr:last');          $('[id^=item_number]:last').attr('id', 'item_number' + counter);         $('[name^=item_number]:last').attr('name', 'item_number' + counter);          $('[id^=select_product]:last').attr('id', 'select_product' + counter);         $('[name^=select_product]:last').attr('name', 'select_product' + counter);          $('.selectpicker').selectpicker('refresh');         counter += 1;                            return false;                        });                                  });     

but on dynamically created rows, of 'select' boxes have select picker box drop down. when change value in 2nd+ select box, changes value on first row.

it doesn't matter if row 2 or 3 or whatever. when change selectpicker select box. row 1 gets updated. , rows 2+ stay @ default value.

its tied first row, instead of new (dynamically added) rows.

what doing wrong?

thanks!

found answer, @ least works me. appears had 2 problems.

1) according 'issues' page bootstrap-select found here learned bootstrap select adds div class replace select box. have remove class before can anything. have refresh/reinitialize bootstrap select on new rows have added.

2) after doing that, still couldn't work. turns out clone(true,true). assumed wanted bring event handlers new rows. guess not. seems instead when clone event handlers, ties first row. changing clone() solved issues.

for may run similar issue, here functioning code (at least in firefox).

var counter = 1; $(document).ready(function() {    $('#additemrow').click(function() {        // fix clone() part - must not clone(true,true)       $('#itemmultiinputtable tr:last').clone().insertafter('#itemmultiinputtable tr:last');      $('[id^="item_number"]:last').attr('id', 'item_number' + counter);     $('[name^="item_number"]:last').attr('name', 'item_number' + counter);      $('[id^="select_product"]:last').attr('id', 'select_product' + counter);     $('[name^="select_product"]:last').attr('name', 'select_product' + counter);      // these 2 key lines making work     $('#itemmultiinputtable tr:last').find('.bootstrap-select').replacewith(function() { return $('select', this); });     $('.selectpicker').selectpicker('refresh');     counter += 1;                        return false;                     });                                  });     

i'll note well, works 3 select fields have in form. don't have address each individually because replaces 'select' fields. , clone function provides right data each field.

i'm self-teaching myself go, if notices better, i'm eager learn.

thanks.


Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -