Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error refresh method .Elements doubles after that - bootsrap 5 + vue 2 #2712

Open
andryshok opened this issue Feb 23, 2022 · 4 comments
Open
Labels

Comments

@andryshok
Copy link

andryshok commented Feb 23, 2022

I use bootsrap 5 + vue 2 .
code html

<select id="sb_select1" name="sb_select_mark" class="selectpicker form-control"  data-live-search="true" data-style="btn-select" data-title="title1">
																				
										<optgroup  label="group1" v-if="items.car_marks_full"> 
											<option v-for="(item, index) in items.car_marks_full" data-car-type="1" :data-car-link="'/cars/'+item" :value="item.id">{{ item.title }}</option>
										</optgroup>	
										
										
										<optgroup label="group2" v-if="items.truck_marks_full"> 
											<option v-for="(item, index) in items.truck_marks_full" data-car-type="2" :data-car-link="'/trucks/'+item" :value="item.id">{{ item.title }}</option>
										</optgroup>
</select>		

after vue rendering html i use method
$('#sb_select1').selectpicker('refresh');

after refreshing items have a doubles, vue get correnct items, but selectpicker('refresh') method not work correctly

@andryshok andryshok added the bug label Feb 23, 2022
@jayb611
Copy link

jayb611 commented Apr 22, 2022

Yes i have faced this issue , fix for that is

Add line at 1780 @ render: funcation
this.selectpicker.main.data = [];
Replace line at 2737 @ this.$menuInner.on('click', 'li a', function (e, retainActive) { function
prevData = prevOption ? that.selectpicker.main.data[prevIndex],

Fixed

@SoftCircuits
Copy link

@jayb611 Do you know where I can get the fix? Or is it necessary to install some less or sass code in order to build my own?

@jayb611
Copy link

jayb611 commented Jun 18, 2022

I have already mentioned above where you need to place and replace code to fix this issue, no you do not need SASS code

@tiesont
Copy link

tiesont commented Nov 21, 2022

Not sure what all has changed since @jayb611 posted their comment, but the only consistent fix I've found so far is slightly modifying the buildData function.

In the compiled source, that seems to be line 1657. From the "raw" source, it's line 1633.

Find this switch:

switch (type) {
  case 'data': {
    if (!this.selectpicker.main.data) {
      this.selectpicker.main.data = [];
    }
    Array.prototype.push.apply(this.selectpicker.main.data, mainData);
    this.selectpicker.current.data = this.selectpicker.main.data;
    break;
  }
  case 'search': {
    Array.prototype.push.apply(this.selectpicker.search.data, mainData);
    break;
  }
}

and comment out or remove the check for this.selectpicker.main.data:

switch (type) {
  case 'data': {
    this.selectpicker.main.data = [];
  
    Array.prototype.push.apply(this.selectpicker.main.data, mainData);
    this.selectpicker.current.data = this.selectpicker.main.data;
    break;
  }
  case 'search': {
    Array.prototype.push.apply(this.selectpicker.search.data, mainData);
    break;
  }
}

I have no idea what the performance implications of this will be, but it seems like resetting the this.selectpicker.main.data prevents the option elements from being duplicated. Hopefully someone else comes up with a better fix, but perhaps this helps someone else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants