Jump to content
  • 0

Multi select list box in search - default values


BrianI

Question

Hi

I have a multi select list box as part of my search criteria on a datapage. Is it possible to set a default value for this field with multiple values.

Example for a task list which has status options of Not started, In progress and complete. Can I set the default search on the list to return Not started and In progress?

Thanks

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Hello @BrianI,

Please provide more details:

1) Is the 'Task list' field a Text(255) file (not a List_String)?
So, the result should be:
ZfjAwPX.png

2) Do you have Search and Results on one or separate pages?
3) Do you need to apply these default values once when the DataPage is loaded? 
Because the user can change the search criteria while using the report.

Link to comment
Share on other sites

  • 0
On 4/14/2024 at 11:44 PM, BrianI said:

Hi

I have a multi select list box as part of my search criteria on a datapage. Is it possible to set a default value for this field with multiple values.

Example for a task list which has status options of Not started, In progress and complete. Can I set the default search on the list to return Not started and In progress?

Thanks

Hi @BrianI,

If you use a List String DataType, in the Search form under the Advanced tab, you can set the Default Value to Not Started and In Progress.

image.png.22876fcc8fbb8b1e14cc07a86aa348d6.png

Hope this helps.

Link to comment
Share on other sites

  • 0

Hi, the values are not in a multi list string and I do not want to set it up that way as it has other limitations The values are held in a separate table with other metadata.

@CoopperBackpack

1. yes it's a text255 field type

2. Search and results are on the same page

3. This should just be a default and the user should be able to change the search once loaded.

Thanks

Link to comment
Share on other sites

  • 0

Hello @BrianI,

Thank you for your answers.

1) As a first step, you need to allow multiselection on the Advanced tab:

ylascps.png

2) Then add JavaScript code to the Footer of the Search page.
 

<script>
document.addEventListener('DataPageReady', defaultOptionsHandler, { once: true });
 
function defaultOptionsHandler() {
 const taskListFieldOptions = Array.from(document.querySelector('#Value1_1').options); //Value1_1 is the 1st field

 taskListFieldOptions.forEach((option) => {
    if(option.value == 'In progress' || option.value == 'Not started'){
       option.setAttribute('selected', 'selected');
     }
 })
}

</script>

Please double-check the values that should be compared. In my example, they are 'In progress' and 'Not started'.
Also, change the field ID if needed. On the Search page, the first field has ID = Value1_1, the 2nd field has ID = Value2_1, etc.

If you have questions, feel free to update this thread. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...