I would like to select multiple values in a dropdown. But the dropdown options are asynchronously fetched through REST API. I tried with <select multiple> with ngFor Directive, but it didn't work.
You can always use check boxes in the drop-down list and create a custom directive that check if check box is selected then it triggers some CSS highlight style and furthermore if you don't want to show check-box set its visibility to invisible so it works but only under the hood
(Just an idea)
There would be some extra work like if the drop down goes out of focus you would want the check-boxes to be deselected again so you would also have to check for that in the directive.
Related
I am using React Select Package for dropdown. I wanted the placeholder option to display in the menu option for the user to select it as the dropdown field is not mandatory and the user can leave them empty or unselected.
I have tried many ways. I created a Custom placeholder component to display, but that is also not working. I tried passing a hardcoded value in options array. But that would also not work as i will be getting options from api afterwards.
I have posted my code in Sandbox for better clarity.
https://codesandbox.io/s/stoic-bush-3wstx?file=/src/App.js
I have a drop down with checkboxes besides it. First I want to add a search button in the dropdown. Second, once values are selected, a submit button on clicked should display the selected values with a textbox besides it.
Instead of checkboxes you could select with multiple option.
I would recommend you to use select2 library for your requirement.
It provides search box along with multiple value selection and different styles also which is very handy because it's very difficult to style option tag in html.
Find below the select2 url:
https://select2.org/getting-started/installation
I have a select menu with multiple options. Using jQuery I was trying to pre-populate the dropdown. I've tried using this code:
jQuery("select#attribute150").val("Double").click();
I can visually see that the option has been selected, however the actual price has not been changed. I've also tried:
jQuery("select#attribute150").val("Double").change();
URL to the dropdown is here. The dropdown I want to change is "Size".
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);
I have a textbox which is populated upon clicking a <li> element in a dropdown. This dropdown is populated by a ng-repeat directive on the <li> elements. I have a model to filter the <li> elements on text input.
I want to make sure that when the textbox loses focus, it is either filled with a value from the dropdown or it is reset to a default value. (Simply no custom values are accepted.) Other than checking the value on the text box inside a loop to check for a match in the respective list of items. What other approaches do I have using javascript (preferably the angular way), to easily and effectively address this issue?
(I need the ability to type on the textfield to enable filtering of the dropdown, that and for many other reasons I think cannot use <select> tag.)
I suggest that you still use select but go with Angular-UI's ui-select:
Angular-UI ui-select
It's a wrapper for and AngularJS native implementation of Select2