Auto Select Choices in multi select on load

  • 23 October 2017
  • 8 replies
  • 9 views

Userlevel 6
Badge +13

Hi,

I have a multi select choice box that is populated by semi colon separated values in one of the items column. So on form load the choice control displays the values that exist in that column. This works fine, but what I'd like to do is get these values all selected by default when the form loads, so if a user doesn't want an item selected they have to click on the choice to deselect it rather than having to select all the options other than the one they don't want.

I have hoped that perhaps setting the Default Value to the item column, Nintex might automagically select the values for me, but no. sad.png

I've tried

NWF$('#' + SelectedProductCodes).prop('selected', true);

but this doesn't seem to do anything.

Thoughts?

TIA


8 replies

Userlevel 6
Badge +13

Do I need to perhaps get the javascript to run after the page load? I've tried (window).load and a test alert appears after the page has loaded, but my multi select control does not auto select.

Userlevel 5
Badge +14

try following

NWF.FormFiller.Events.RegisterAfterReady(function () {
    NWF$('#' + SelectedProductCodes + ' input:checkbox').prop('checked', true);
})‍‍‍

‌  select all options‌  populate choice dynamicaly‌ populate choice from listfield‌ form load‌

Userlevel 6
Badge +13

Thanks for the response.

I'll try this in a bit, at the moment I'm on another issue, which you've answered for other people, but I can't quite get to work.

I have a SQL Request control rendered as Multi select checkboxes. I'm trying to write the selected values of the control into a text field and then clear the selected check boxes in the multi select. I've got the code to write the values into the text box, but I can't clear the check boxes. Should this behave the same way as a normal choice control do you think?

I've tried this

NWF$(".selProductCodes option:selected").removeAttr("selected");

and a few other things (where selProductCodes is the javascript variable name of my SQL Request control)

Any suggestions much appreciated.

Userlevel 5
Badge +14

if  'selProductCodes' is javascript variable then selector has to be NWF$("#"+selProductCodes ....

I do not have at hand a system where I could check how SQL Request control is rendered, just blindly what does following statement return? does it equal to number of control's options?

NWF$('#' + selProductCodes + ' input:checkbox').length‍

if it returns zero, try

NWF$('#' + selProductCodes).length‍‍

if even this retirn zero, it means the control is not recognized by javascript variable and there is something wrong with your configuration

if this doesn't bring you on track, are you able to copy and post DOM model (HTML markup) of SQL Request control from developer console?

I may try to look on it.

Userlevel 6
Badge +13

Our first effort returned 0 but the second returned 1, however, I had multiple options selected when it returned 1 so not sure if this is correct or not.

var choices = (NWF$('#' + selProductCodes).val());

This successfully retrieves all the values selected from the control, so we're obviously accessing the control ok, just not able to reset the control to deselect all.

Just to explain I am using the control as a search results field, it returns results based on a search term entered in a text box, executing a stored procedure that performs a free text search of a product file.

Just below there is a button that users click to commit the selected items into a text box so they can then perform another search and when they click the button again the new selections will be added to the text box as well. So I need to clear down the selected items from the search results to avoid the users adding the same products twice. The value that triggers the search is actually a calculated control as is concatenates a code based on the dropdown they select at the top of the form, with their search term, but only when the search term is longer than 3 characters. So an alternative route I guess is to clear down the search box rather than the search results checkbox? Ignore that, I tried it and it seems programmatically clearing the search box won't work, it seems that you have to manually tab or click out of the search box to trigger the stored procedure to execute. So I will need to clear the search results or the checked items.

Having heard the scenario, do you think I'm approaching this correctly or are there alternative approaches you'd suggest?


Thanks

Userlevel 5
Badge +14

it should have returned number of checkboxes within the control (regardless of whether they are selected or not).

but since SQL request is executed dynamically it's important when you issued the command - you should execute it after the control was already populated.

I tried it and it seems programmatically clearing the search box won't work, it seems that you have to manually tab or click out of the search box

after you clear the search box value/content, make a following call, it should invoke recalculation of dependent formulas (if that your restriction of at least 3 characters will not block it)

NWF$('#' + jsvarSearchBox).focusout();
Userlevel 6
Badge +13

Thanks

Your original solution solved my issue of getting the multi choice check boxes defaulted to selected and your subsequent help allowed me to come up with a solution to clear the search results.

Userlevel 5
Badge +14

glad I cloud help.

the (1st) half was quite easy, the (2nd) half just a guess happy.png

Reply