How to add selected items from a dropdown to a custom state?

I’m struggling to add a list of items selected from a multiselect dropdown to a custom state.

I thought this is a relevant method, but it seems not: How To Make A Custom State (which is a list of things)?.

I feel I have to ‘set list’, but can only minus list or plus item.

image

Hi there, @andrew36… if I understand your post correctly, I believe the merged with operator is what you need on this one.

Best…
Mike

1 Like

Thanks @mikeloc, that was it! I didn’t know about that operator. Not that obvious a solution to me.

However, I don’t know how to apply this custom state to filter a repeating group. I thought it would be possible with the below, but apparently not. Do you know why?

What does the issue checker say? You might need to use an advanced filter that does a count > 0 of the intersect of the lists.

@mikeloc Actually, I don’t think your answer is what I need, or I need some more logic, because deselecting items does not remove the items from the custom state. Do you have idea how to do that?

image

How do I get to an advanced filter?

Can you just set the custom state list to the multi-dropdown’s value as opposed to setting the state to its current value plus or minus another list?

The ‘Contains’ comparison checks to see if a single defined thing is present in the initial list of things…

i.e. does the Aircraft Class field (which presumably is a list) contain the single thing you define in the expression…

It can’t be used to compare lists to lists…

For that you’ll need to use either ‘Contains List’ or ‘Intersect with’ (depending on exactly what you’re trying to do)… both which can only be used in an advanced filter.

1 Like

Nope, I’ve tried that…

Taking a step back… what is the custom state supposed to be holding? Is it the list of things that have been selected from the multi-dropdown, and when those selections are changed, the custom state should be updated to include only the current selections?

I’m not sure what you tried, but you should be able to set your custom state directly to the multi-dropdown’s value, assuming they are the same type. It should be as simple as this example where I am setting a custom state to a list of users selected in a multi-dopdown.

1 Like

When you have a field like that, the action that will happen IS “set list”.

If you then want to add or remove an item you set the value to an expression that is “the current value”:plus item or “the current value”:minus item.

@keith, unless you know something I don’t know, you can’t use set list on custom states.

Edit: Ah, I get what you said now… my bad.

1 Like

The action is Set State. The value you put in the field becomes the value of the state. You are in fact setting the state.

If you want to modify a previously set state, you just reference the state and modify it.

Like if it’s a number:

Set state a to 5.

Now you want it to be 7?

Let’s say the state is “page’s num-state”. Set State of page’s num-state to “page’s num-state +2”.

It’s exactly analogous to;

a = a+2

Yes, your first paragraph is exactly what I need to do. I have just changed it to directly reflect the dropdown list’s value, but I now can’t filter properly! I don’t know how to set up the advanced filter :confused:

Well, that’s an entirely different question, and it wasn’t the point of your topic… so, at least this topic is solved. :slight_smile:

What are you trying to show in the repeating group? Only things that have all of the selections in the custom state? Or things that have any of the selections in the custom state? If it’s the former, the advanced filter might be something like This Aircraft class contains list requests_all's CS Aircraft class. If it’s the latter, it might look like This Aircraft class intersect with requests_all's CS Aircraft class:count > 0.

Yes, topic is solved by you now, thank you :smiley:

Your suggestion to ‘This…’ and ‘intersects with’ solved my filter issue too :slight_smile: However, I get a blank list, until I select a dropdown thing. I thought this wouldn’t happen with the ‘Ignore empty constraints’ selected. Unselected, it’s still blank without the CS populated.

1 Like

Ignore empty constraints doesn’t work with advanced filters, so one way you can go is to add a condition that changes the data source of the repeating group to show all things when the custom state is empty.

2 Likes

That did it - thanks for all this :smiley:

1 Like

As @mikeloc points out, Ignore Empty Constraints does not work on advanced filters…

So, one way to get around that is to do what Mike said and add a conditional datasource when the custom state is empty (or not empty)…

There is a way to avoid having to use conditional data sources though (which, in this case might not be an issue, but if you have multiple constraints it can start to get messy with lots of conditional datasources)…

So, an alternative, is to use an ‘Or’ operator to add to the filter condition, such that the Thing in the list will be included when the custom state is empty…

So, in your case the Advanced filter would be: This Request's Aircraft class intersect with requests_all's CS Aircraft class: count > 0 or request_all's CS Aircaft class: count is 0

2 Likes