Choices
Choices copied to clipboard
Cannot use Choices if rendered from iframe
Describe the bug Disclaimer: To be honest, this is a kinda special setup.
I have a modal window whose content contains a select
field that is used to initialize Choices.js. There are two scopes where this modal may be opened:
- in a simple standalone view
- in a more complex environment with an
iframe
, where the modal is rendered in the top frame
In the latter case, I get the error "Expected one of the following types text|select-one|select-multiple". The issue is that the instanceof
check for the passed element to initialize Choices.js does not work in case of an inter-frame communication. In my tests it was safe to check passedElement.constructor.name
instead.
Since the fix is rather easy I'll push a PR ASAP.
To Reproduce Steps to reproduce the behavior:
- In the iframe, have a callback that initializes Choices.js
- Open a modal with the matching
select
element on the top frame - Execute the callback
- See "Expected one of the following types text|select-one|select-multiple"
Expected behavior I expect that Choices.js works in the scenarios mentioned above.
Desktop (please complete the following information):
- OS: Fedora Linux 36
- Browser Chrome
- Version 105
+1. I have a similar problem.
+1 for me as well, I found that the issue is probably because of the use of instanceOf
on ChoiceJS before initialization. On iframe this is unreliable. There could be also be some potential issues when the proto chain has been modified for some reason as well.
I think the best solution here would be to replace instanceOf check for something else like nodeName or anything else that is constant and persistent.