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

$el.selectpicker('val',value) causes errors e.stopPropagation is not a function #1366

Closed
fusionbeam opened this issue Apr 15, 2016 · 9 comments

Comments

@fusionbeam
Copy link

fusionbeam commented Apr 15, 2016

bootstrap-select 1.10.0
jquery 2.2.3


anyone encountering the same issue?

@arambadk
Copy link

Same here

@caseyjhol
Copy link
Member

See guidelines for contributing.

Bug reports

A bug is a demonstrable problem that is caused by the code in the repository.
Good bug reports are extremely helpful - thank you!

Guidelines for bug reports:

  1. Use the GitHub issue search. Check if the issue has already been reported.
  2. Check if the issue has been fixed. Try to reproduce it using the latest master or development branch in the repository.
  3. Provide environment details. Provide your operating system, browser(s), jQuery version, Bootstrap version, and bootstrap-select version.
  4. Create an isolated and reproducible test case. Create a reduced test case.
  5. Include a live example. Make use of jsFiddle or jsBin to share your isolated test cases.

@kovart
Copy link

kovart commented Apr 20, 2016

I had the same issue, but it solved after I call refresh function before changing
$(element).selectpicker('refresh'); $(element).selectpicker('val', 1);

@maximelebreton
Copy link

+1

@PhilPJL
Copy link

PhilPJL commented Nov 18, 2016

I have this issue also
snip

Using jQuery 1.12.4 and bootstrap-select 1.11.2 on IE 11 or IE Edge

picker.selectpicker('val', init);

fails,

but

picker.val(init);
picker.selectpicker('refresh');

succeeds.

If I update jQuery to 3.1.1 then either way succeeds.

@caseyjhol
Copy link
Member

Closing this until somebody can follow guidelines for contributing.

@PhilPJL
Copy link

PhilPJL commented Nov 22, 2016

@caseyjhol: Please re-open.

Here's my first attempt at using jsBin https://jsbin.com/muvuguy/347/edit?html,js,output
The issue only appears in $(document).ready and when using jquery < V2.

In the demo uncheck 'auto-run with JS'.
Click 'run with JS'. The select picker is initialised.
Now comment out the jquery-3.1.1 script block and uncomment the jquery-1.12.4 block.
Click 'run with JS'. The select picker is not initialised.
However, using either of the 'test' buttons does initialise the picker for either version of jquery.

@caseyjhol caseyjhol reopened this Nov 22, 2016
@caseyjhol
Copy link
Member

caseyjhol commented Nov 22, 2016

The reason this works with jQuery 3.0.0 and above is $(document).ready() is now fired asynchronously (see jquery/jquery#3197). Because of the test page's small size, $(window).on('load') is fired before $(document).ready(), which allows bootstrap-select to initiate first, before setting the value in $(document).ready(). We run into this issue (attempting to set the value of the select before it's even initialized) in situations where it takes longer to load the page, or with any version of jQuery prior to 3.0.0. A workaround in the meantime is to use $(window).on('load') instead of $(document).ready().

@caseyjhol
Copy link
Member

Duplicate of #1167.

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

6 participants