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

Doesn't reset on form reset #1315

Closed
ouroborus opened this issue Feb 28, 2016 · 16 comments
Closed

Doesn't reset on form reset #1315

ouroborus opened this issue Feb 28, 2016 · 16 comments
Milestone

Comments

@ouroborus
Copy link

When you reset the form (via reset button), the underlying <select> resets, but the control doesn't update to match.

@ubeyou
Copy link

ubeyou commented Mar 8, 2016

try this

$('[type=reset]').click(function() {
            $('#status').selectpicker('val','your_default_value');
        });

@ouroborus
Copy link
Author

The default value is different across several elements. This works for me:

$('form').on('reset', function(event){
  $('.selectpicker',this).each(function(index, element){
    var $this = $(this);
    setTimeout(function(){
      $this.selectpicker('val',$this.val());
    },0);
  });
});

Still, I believe there should be some sort of integration such that the control behaves as the control it overrides.

@caseyjhol
Copy link
Member

This should work:

$('form').on('reset', function() {
  setTimeout(function() {
    $('.selectpicker').selectpicker('refresh');
  });
});

@ouroborus
Copy link
Author

My understanding is that you can have more than one form on a page and that reset buttons (or reset events) only reset the form they are associated with. Your code would reset selectpicker items outside of just those associated with the form that the particular reset button (or reset event) is associated with.

Seperately, I do see that you're using a different command, 'refresh', to selectpicker.

@ouroborus
Copy link
Author

Ah, I see... Slight modification to take multiple forms into account as well as dropping the each (as @caseyjhol suggests):

$('form').on('reset', function() {
  var _this = this;
  setTimeout(function() {
    $('.selectpicker',_this).selectpicker('refresh');
  });
});

@giro83
Copy link

giro83 commented Jul 4, 2016

I like this solution:

$('.selectpicker').selectpicker('refresh');

and I am using it successfully (thanks, caseyjhol).

But I agree with previous comments that the regular Reset button should work out of the box with bootstrap-select. It would be nice if bootstrap-select could be improved so that no additional fiddling is necessary.

@Roukmouth
Copy link

+1

1 similar comment
@aval-sarri
Copy link

+1

@Jogai
Copy link

Jogai commented Mar 24, 2020

Please release this. Its default behaviour, and a long standing issue...

@caseyjhol
Copy link
Member

This change will be a part of the v1.14.0 release. This issue will be updated after it's made available.

@caseyjhol
Copy link
Member

Released in v1.14.0-beta!

@soyxan
Copy link

soyxan commented Mar 11, 2021

For me is still not working, when I call $('#myform')[0].reset(); all the standard elements inside the form are reseted but not the multiselect, it still show the values separated by comma.

I tried with $('.selectpicker').selectpicker('refresh'); but it is not working.

I am on bootstrap@4.5.3 + bootstrap-select@1.14.0-beta

@caseyjhol
Copy link
Member

@soyxan Can you link me to an example?

@soyxan
Copy link

soyxan commented Mar 11, 2021

In the following link you can check 2 issues I am facing:

https://codepen.io/soyxan/pen/JjbwzKR

Thanks!

@soyxan
Copy link

soyxan commented May 10, 2021

Why is this issue closed, both of the issues on my previous post are still not solved, right?

Thanks!

In the following link you can check 2 issues I am facing:

https://codepen.io/soyxan/pen/JjbwzKR

Thanks!

@caseyjhol
Copy link
Member

@soyxan In your example, you're not calling reset(), you're calling reset, which is why it's not working. Also, mobile=true opens the native select menu. On desktop, for multiple selects, there is no menu, so the menu doesn't open up. That's why it's a feature designed for use on mobile devices.

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

No branches or pull requests

8 participants