How to filter items by “choice” component

I have a list of sites, across several countries, that I display in a list. I want to be able to filter and only show the sites for the country that the user is currently in.

  1. Is there a way I can do this automatically by getting the user’s location/IP and matching it to the country?

  2. How would I do this with the choice component?

  3. If I had to ask the user for their country, is there a way I could store it so that I wouldn’t have to ask them again?

Thank you so much in advance for all and any answers!

Hi,

  1. No idea

  2. Here, your best friend should be the filter on the choice components.

  • 2 columns : Country with sites in front of each country
  • 2 choice components: first with source value “country”, and second “sites”
  • On the “sites” choice component, apply a filter on “country” is “screen > country” (which means the list of sites will be restricted to the country selected in the screen).

  1. You need to use the user profile
  • A dedicated tab, with at least Name, Email, Picture + in your case “Country”, “Sites”
  • In the User section on your app (top of the hamburger menu), make sure that the fields match on the right part of the screen
  • Then add components to collect the information: name etc + the 2 choice components mentioned above

image

image

1 Like

There are some APIs that supports this, but I haven’t tried this with the Experimental Code column so I’m not sure it will work.

I think you’d better follow @AyS_0908’s guide. Basically ask for the user’s country in the onboarding process and filter your sites accordingly.

1 Like

Hi, thank you so much for your reply.

So the one caveat for this app is that it is a public app. There are no user accounts and we don’t want to store user info or ask them to sign up.

Is there a way we could use one choice component to ask a user what country they are in, and then show them a list of all the sites that have the same country?

You can add a text component/choice component pointing to a user-specific column, then filter based on that column.

Could you please assist me here? I have a choice component and the sites below. How would I apply the filter properly?


The filter should be something like:

Site_country_name is screen’s site_country_name_user_input. Assuming you’re letting the user write to the input column, and you have a column name in the sheet where you are storing sites.

Yeah I’m not letting the user write to anything. I want to display a list of sites based on the country a user picks. The user then clicks on a row in the list that opens a link.

So, I want to filter a list of predetermined sites based on a list of predetermined countries that said sites exist in.

You must let the user write that choice to a column before being able to filter anything, like I said above.

Hola,

I found a script days ago which finds the user’s IP address and its location and I think it can help you.

Unfortunately I didn’t test it but I am going to search it again and test it to know if we can use it in an Experimental Column.

I let you know in the afternoon!

Saludos

1 Like

Thanks very much, I look forward to hearing back from you!

Hola de nuevo!

You need to follow these steps: :slightly_smiling_face:

1- Use this URL to get the user’s IP and country https://api.country.is/

You will see something like:

{“country”:“VE”,“ip”:“190.39.04.102”}

2- Create a new Experimental Column using this repl created by Mark Probst: https://glide-yes-code-hell-yes.markprobst.repl.co and put the following code:

const data = await fetch(`https://api.country.is`)
const json = await data.json();
return json.country

your screen should look like this but showing your right country code instead:

image

I’m in Venezuela so my code is shown as VE.

I hope it helps you @Slade_Rose

Saludos

3 Likes

Thank you so much! This was such a great and simple solution to the problem. Thank you!

1 Like