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

Sanitizer throws: bootstrap-select.js:1250 Uncaught TypeError: Cannot read property 'data' of undefined #2231

Closed
esamo opened this issue Mar 13, 2019 · 9 comments

Comments

@esamo
Copy link

esamo commented Mar 13, 2019

Howdy!

Error

Uncaught TypeError: Cannot read property 'data' of undefined
    at scroll (bootstrap-select.js:1250)
    at Selectpicker.createView (bootstrap-select.js:1125)
    at Selectpicker.setSize (bootstrap-select.js:2010)
    at HTMLButtonElement.<anonymous> (bootstrap-select.js:2303)
    at HTMLButtonElement.dispatch (jquery-3.3.1.min.js?1292635420:2)
    at HTMLButtonElement.y.handle (jquery-3.3.1.min.js?1292635420:2)
              if (that.options.sanitize) {
                elText = element.lastChild;

                if (elText) {
                  elementData = that.selectpicker.current.data[i + that.selectpicker.view.position0].data;

                  if (elementData && elementData.content && !elementData.sanitized) {
                    toSanitize.push(elText);
                    elementData.sanitized = true;
                  }
                }
>             }

View
When you click on the button, drop down opens with white background and nothing more.
With the sanitizer off, there is no error and dropdown looks as expected.

How to reproduce
This report is based on v1.13.6 but also happened with v1.13.7.
With specific but common options provided, sanitizer will throw given error.


Data (I had to remove the labels but error is triggered anyway so it is about keys maybe):

array:78 [▼
  2887 => ""
  2890 => ""
  2893 => ""
  2896 => ""
  2899 => ""
  2902 => ""
  2905 => ""
  2908 => ""
  2911 => ""
  2914 => ""
  2917 => ""
  2920 => ""
  2923 => ""
  2926 => ""
  2929 => ""
  2845 => ""
  2782 => ""
  1583 => ""
  2710 => ""
  1918 => ""
  2717 => ""
  282 => ""
  2779 => ""
  2780 => ""
  2773 => ""
  2786 => ""
  2666 => ""
  2787 => ""
  1674 => ""
  2719 => ""
  3022 => ""
  2770 => ""
  1539 => ""
  3031 => ""
  229 => ""
  152 => ""
  129 => ""
  2776 => ""
  2777 => ""
  390 => ""
  153 => ""
  2944 => ""
  2774 => ""
  760 => ""
  406 => ""
  2718 => ""
  2778 => ""
  2783 => ""
  1820 => ""
  1885 => ""
  942 => ""
  2715 => ""
  2643 => ""
  2738 => ""
  2771 => ""
  2772 => ""
  2753 => ""
  131 => ""
  250 => ""
  1915 => ""
  128 => ""
  949 => ""
  1575 => ""
  2711 => ""
  130 => ""
  1621 => ""
  413 => ""
  234 => ""
  283 => ""
  245 => ""
  246 => ""
  1566 => ""
  1568 => ""
  940 => ""
  154 => ""
  2076 => ""
  1346 => ""
  1825 => ""
]

Regards.

@caseyjhol
Copy link
Member

Can you give me some more info about your setup? I've recreated your select based on what you've told me and it's working fine here: https://plnkr.co/edit/EiAVvxRMD1XoS1UgYWQZ?p=preview.

Bug reports must include a live demo of the problem (please feel free to use my linked Plunker for your reduced test case). I also need your:

  • Bootstrap version
  • specific browser and OS details.

@vikrampariharcodereadr
Copy link

vikrampariharcodereadr commented Mar 14, 2019

I am facing same issue .
Uncaught TypeError: Cannot read property 'data' of undefined

Exactly error in this line
elementData = that.selectpicker.current.data[i + that.selectpicker.view.position0].data;
line no. 1260
"bootstrap-select": "^1.13.6",
"jquery": "^3.3.1",
"bootstrap": "^4.3.1",

@esamo
Copy link
Author

esamo commented Mar 14, 2019

Bootstrap v3.3.7
jQuery v3.3.1
Chrome v72.0.3626.121
Win10 x64

@esamo
Copy link
Author

esamo commented Mar 14, 2019

               element.selectpicker({
                    dropupAuto: false, // Always drop to bottom
                    noneSelectedText: typeof lang !== 'undefined' ? lang.common.please_select
                        : null, // Apply polite placeholder
                });

@jbtronics
Copy link

I am facing the same issue. I could reproduce the issue in an Plnkr environment: https://next.plnkr.co/edit/R4sSYX1zoUrbggGK (sry, i have tried to shorten it, but if i cut some more option tags, then the bug does not occur)

The error seems only to occur, when one of the middle options is selected. I would guess this bug is somehow related to the position of the selected option in the select element...

@esamo
Copy link
Author

esamo commented Mar 14, 2019

Yes I can confirm that when I removed the option which was selected then the bug was not appearing. But not sure what does this mean.

caseyjhol added a commit that referenced this issue Mar 14, 2019
…ll scroll to that option, and set position0 higher than 0. If virtualScroll is not enabled, position0 should always be 0 when retreiving elementData.

#2231
@caseyjhol
Copy link
Member

Released in v1.13.8!

bestpractical-mirror pushed a commit to bestpractical/rt that referenced this issue Sep 6, 2019
We encountered an issue of the old version with an error message like

    Uncaught TypeError: Cannot read property 'data' of undefined

See also snapappointments/bootstrap-select#2231
@kvvaradha
Copy link

I have the same issue and i just updated it to new plunker.
https://plnkr.co/edit/gGsG7IV0EdRVLtYr kindly look around it and help me to get a solution.

@caseyjhol
Copy link
Member

@kvvaradha I'm not seeing that error in that Plunker. What are the steps to reproduce?

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

5 participants