bootstrap-select: Setting `val` doesn't work

Using the following $('.selectpicker').selectpicker('val', '1'); to preset the value of my select is returning the following error.

Uncaught TypeError: e.stopPropagation is not a function

The error is pointing to line 258 in bootstrap-select.js if it helps. i.e.

if (e) {
    e.stopPropagation();
    e.preventDefault();
}

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 16 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Replace the conventional code:

 $target.selectpicker("val", value);

For this:

 $target.val(value);
 $target.selectpicker("refresh");

I tried the following and it works.

 $target.selectpicker("refresh");
 $target.val(value);
 $target.selectpicker("refresh");

@D-Skywalker 's suggestion did not work for me, and I built on that to include additional refresh.

I believe there is some sort of delay induced by $target.selectpicker("refresh"); which is causing this issue.