This topic is locked
[SOLVED]

 multi-select setting options

9/12/2020 11:07:49 PM
ASPRunner.NET General questions
H
heilmanmd author

have a multi - select field
using browser dev tools see it's handled by chosen ( https://harvesthq.github.io/chosen/ ) multi-select plugin
have no issues working with normal selects via jquery for setting , adding, removing options, etc... ( see below example )
$('select[id^="valueREGION"]').find('option').remove();

$('select[id^="valueREGION"]').prepend('<option value = "">Please Select</option>');
if (numregions > 0) {
for (i = 0; i < numregions; i++) {

region = regionsarray[i];

region = region.trim();

$('select[id^="valueREGION"]').append($('<option>', {

value: region,

text: region

}));
if (i == 0) {

firstreg = region;

}

}

}
but for multi-select selects... hum... and since being handled by chosen multi-select plugin
not getting very far
reviewed the chosen documentation in the above url... but not much help...
anyways here's what see via dev tools in Edge for multi select field
(screen snap shot)

https://www.screencast.com/t/zpkpOjttBwO
( dev tool outer html )

<span id="edit1_ACCESSES_0" class="bs-ctrlspan rnr-nowrap "><input id="type_ACCESSES_1" type="hidden" name="type_ACCESSES_1" value="multiselect"><select id="value_ACCESSES_1" size="1" name="value_ACCESSES_1[]" multiple="" class="form-control" style="display: none;"></select><div class="chosen-container chosen-container-multi" title="" id="value_ACCESSES_1_chosen" style="width: 100%; position: static;"><ul class="chosen-choices">

<li class="search-field">

<input class="chosen-search-input default" type="text" autocomplete="off" value="Please select" style="width: 93px;">

</li>

</ul>

<div class="chosen-drop" style="width: 555px; top: 34px; left: 15px; display: none;">

<ul class="chosen-results"></ul>

</div></div></span>
I've tried doing following to set no results / options per doc

$(".chosen-select").chosen({no_results_text: "Oops, nothing found!"});
where my best guess for the element would be

$(". edit1_ACCESSES_0").chosen({no_results_text: "No Accesses"});
Any suggestions / thoughts on how to set a multi-select option most appreciated.
Thanks

Mark

H
heilmanmd author 9/12/2020

ok...
I got something to work... same o same o for setting the options via jquery works fine
if ( numaccesses > 0 ) {

$('select[id^="valueACCESSES"]').find('option') .remove();

$('select[id^="valueACCESSES"]').prepend('<option value = "">Please Select</option>');
for(i = 0; i < numaccesses ; i++)

{

access = accessarray[i];

access = access.trim();

$('select[id^="valueACCESSES"]').append($('<option>', {

value: access,

text : access

}));

}
BUT SINCE IT's CHOSEN MULTI-SELECT YOU GOTTA TELL IT TO UPDATE AFTER CHANGING OPTIONS...
// this updates the chosen select .. after having loaded, etc...
$('select[id^="valueACCESSES"]').trigger("chosen:updated");
oh yeah... oh heavens... oh thank goodness got that working...
Maybe I should post a whole thing on multi-select handling tricks... ?? hum...
Best

Mark