Closed jaapmurre closed 5 years ago
Hi, thank you for your feedback. Could you provide a jsfiddle (e.g. editing https://jsfiddle.net/u2xf6bew/3/ )?
Actually the simplest code should work:
var $q = $('#originalInput').find(":selected");
As usual bootstrap/jquery plugin BsMultiSelect has "unobtrusive" API. Means developers relly on original input element (even if it hidden) - so use its triggers and properties.
This doesn't seem to work correctly. It completely ignores any selections I make.
<select multiselect="" class="form-control" name="newUserMemberSites" id="newUserMemberSites" style="display: none;">
<option value="1">Option A</option>
<option value="100">Option B</option>
</select>
$('select[multiselect]').bsMultiSelect({
selectedPanelDefMinHeight: 'calc(2.25rem + 2px)', // default size
selectedPanelLgMinHeight: 'calc(2.875rem + 2px)', // LG size
selectedPanelSmMinHeight: 'calc(1.8125rem + 2px)', // SM size
selectedPanelDisabledBackgroundColor: '#e9ecef', // disabled background
selectedPanelFocusBorderColor: '#80bdff', // focus border
selectedPanelFocusBoxShadow: '0 0 0 0.2rem rgba(0, 123, 255, 0.25)', // foxus shadow
selectedPanelFocusValidBoxShadow: '0 0 0 0.2rem rgba(40, 167, 69, 0.25)', // valid foxus shadow
selectedPanelFocusInvalidBoxShadow: '0 0 0 0.2rem rgba(220, 53, 69, 0.25)', // invalid foxus shadow
inputColor: '#495057', // color of keyboard entered text
selectedItemContentDisabledOpacity: '.65' // btn disabled opacity used
});
However, when I make my selections via
$('#${param.id}MemberSites').find(":selected").each(function(index)
I only get whatever I selected by default (selected after initialization using jquery). If I remove all of the selections, this return empty. If I select all the options, I still only get the default selected one.
Am I doing something wrong or ...?
It works. https://jsfiddle.net/Lxr15ywt/3/ . press click me. and please provide your jsfiddle
When I look at your fiddle and click the button, it says "3"; however, there are only 2 selected.
EDIT After I select a 3rd one and click the button again, it says "4". It's always one more than what it should be. I'm failing to see how that means it works.
UPDATE He is a fiddle: https://jsfiddle.net/edwolfe/eLnu5cvb/#&togetherjs=a9l3o2D8wo 1) click "click me" you will see "1" 2) select "Option B" 3) click "click me" again 4) it still shows "1"
There was one "Hidden selected" option in my fiddle. Removed as confused. Now checking yours
He is a fiddle: https://jsfiddle.net/edwolfe/eLnu5cvb/#&togetherjs=a9l3o2D8wo
changing <select multiselect
to standard multiple="multiple" solves the problem.
changing
<select multiselect
to multiple="multiple" solves the problem.
what is wrong with using multiselect? isn't that valid markup?
'multiselect' attribute is not an HTML standard. without "multiple" we have "combobox. May be some of internally used jquery functions do not expect that we apply multiselect functionality to something that is "combobox"
ok; i changed it and it is working. Thanks!
Problem
When I use jquery on the orginal multiselect, the val() function only gives a single value. As far as I could see the original
Solution (?)
I now solved it like this:
This works (returns the selected values as a comma-delimited list) but is brittle: If a value has a hyphen this would not work.