select2 open without focus - javascript

I use jquery select2 in my project and need to open the select2 all the time.
(link for this plugin: https://select2.github.io/)
I tried $('#select2id').select2("open"), but this keeps focusing on this element. I cannot focus on other inputs in this page. Any other ideas?
Here is the example: http://jsfiddle.net/vff6t9aa/

Related

Controlling Select2 programmatically without jQuery

How to control select2 component programmatically without jQuery? The code is going to be executed using Selenium and since I don't have access to the jQuery object (it's bundled with Webpack), it has to be controlled using pure JS.
I tried simulating user click like this:
document.getElementById('select2').click()
but it doesn't open. What I'm trying to achieve is:
open Select2
type something inside its search box to trigger the ajax call and shows possible options
select an option by text
You can try this workaround: document.querySelector("#example + span > .selection > span") and then trigger click. Fiddle to check: https://jsfiddle.net/zeLbk6s3/2/
You have to trigger "click" on proper element.

Selectric search within results

I'm using selectric - plugin for replacing select in forms and I'm struggling with the add search option, sadly this plugin does not come with such a feature.
I got to the point where I can create an input over label and refresh options after typing something, but it does not work as I expect. I got to this point:
jsfiddle http://jsfiddle.net/fcamjb57/
The issue is as you click the input, the whole select closes.

jQuery UI datepicker - closes with a custom selectmenu

I have jQuery UI installed and am currently having an issue with the datepicker widget. I have the calendar displayed when you click on the icon and it is generated. The calendar has a select menu for Month and Year. I am using the jQuery UI custom select menu.
When I go to make a selection for the selectmenus, the option selected closes/discards the entire datepicker.
My assumption is that there is an event being triggered to close the datepicker when you click outside of the main widget. The custom selectmenu is not the standard 'select' menu with 'options', but rather a bunch of 'spans'. The code is simply acknowledging the click on the custom selectmenu options as a field outside of the original widget.
Any suggestions or assistance to prevent this trigger or help me locate where this event is firing from, feel free to help me out. Thanks

JQuery Mobile selectmenu() multiple option true/false -> not refreshing the displaying of choices

Regarding JQuery and JQueryMobile,
Code is in this JSFiddle link: https://jsfiddle.net/nyluje/jg5cgw76/7/
I use a flipswitch to change, if a select object has the attribute multiple or not.
At first the flipswitch is off and the attribute multiple does not apply on the select.
If I use the select, I can choose only one single option (this works fine).
Then I turn the flipswitch to on. Now with the code I implemented in the function setSelectAccordingToFs() the attribute multiple is added to the select and it is then possible to pickup multiple options. But one notices that the pop-up, which is not a native menu one, does not display the multiple select correctly, like on this picture:
It keeps on displaying the single select panel. Which does allow to add up options, but does not provide the possibility to take off some:
Hence I wonder: How to refresh the select panel menu used by a select, depending on the attribute multiple value:'off' or 'on', on that select tag?
Any idea?
Ok I found the solution. I implemented it in this version of my JSFiddle: https://jsfiddle.net/nyluje/jg5cgw76/8/
The trick:
Using the option 'refresh' wasn't enough. To (really) refresh the selectmenu and include the panel in this refresh, the 'destroy' and 'enable' functionnalities have to be used. So at the bottom of my function setSelectAccordingToFs() I added something like that:
targetSelect.selectmenu('destroy');
targetSelect.selectmenu();
targetSelect.selectmenu('enable');
targetSelect.selectmenu('refresh',true);

bootstrap multiselect drop down is not dropping down

I'm using the bootstrap multiselect plugin and binding the data to it with knockout js. It is in this jsfiddle. The options actually do get data-bound to the multiselect - You can confirm this by right clicking the multiselect element in the jsfiddle output window and inspecting it, and the <option>'s are indeed there. However, clicking the multiselect element does not cause the dropdown to drop down.
The bootstrap multiselect does not seem to know that it has <option>'s in the <select>, this is proven when I use the disableIfEmpty configuration option, it disables the multiselect permanently. Why does the bootstrap multiselect not know that it has options, thus causing it to not open the drop down?
jsfiddle here
You can only instantiate your multiselect widgets after knockout has done its rendering, which is basically after your apply bindings.
To get the idea, check out this forked fiddle: http://jsfiddle.net/r0kbch7u/
I've basically moved the $("#category-select").multiselect() code from your CategorySelect constructor to your document loaded event listener.

Categories