Skip to main content

Search constraints (Lesson 3.7)

In this lesson, we’re going to set up a simple search interface drawing from the “Trip type” option set we set up in the previous lesson.

Sofia Maconi avatar
Written by Sofia Maconi
Updated today

Transcript

In this short lesson, we're going to learn how we can filter a list of things from a dynamic input like this selectable list.

We have already encountered search constraints ever so briefly when we set up our data source for this vertical list of trips on our trips view. We added this Created By search constraint so that we only saw the trips created by the currently logged-in user.

If I remove that, I would see all these trips, including ones that haven't actually been created by the user who's logged in.

We can also add other search constraints. For example, I might want to view only trips where the type is Family and Friends.

One way I find helpful to understand how search constraints work is to think of each constraint as a question asked to every trip in the search. Only if the trip answers yes to each question will it be displayed.

For example:

  • Are they created by the current user? Yes → next question.

  • Are they Family and Friends? Yes → displayed.

These search constraints stack, so only trips matching all constraints are returned.

Testing the app shows the expected behavior: one Family and Friends trip created by the current user is displayed.

In many cases, we don’t want to predefine the filter value. We want it pulled dynamically from some input.

To demonstrate this, I add a Selectable List element inside the header and call it Trip Filter.

Set this up like before: pull all entries from the Trip Type Option Set. Set the type of choices to Trip Type, the choices source to All Trip Types, and the display value to Current Item’s Display Value.

This creates a basic list of trip types.

Next, hook this selectable list up to the data source of the trips list. Add a new constraint in the search: Type = Selected Choice of Trip Filter.

Testing shows something interesting: no trips appear until a filter is selected. Selecting a type displays the corresponding trips.

If I remove the selection, nothing appears, which is unintuitive. Users expect that if no filters are selected, all trips should display.

The solution is to tick Ignore empty constraints. This makes the data source behave as if the selectable list doesn't exist when no value is selected.

Now, all trips are returned until the user selects a filter.

This is a good start, but we want a smoother filtering user experience. We’ll set that up in the next lesson.

Did this answer your question?