Page 1 of 1

Lookup Field Advance Customization help

Posted: 2020-11-27 04:31
by sathukorala
I need some guidance in the below scenario, please
- I make a table with a country name column and city name column
- User selects a country as a lookup field in the second table form (eg. select Australia)
- Then the below field "city" should only show cities in Australia as a dropdown.

How can I do this?
Can't use advanced lookup field SQL query since the record is still not entered to the database.

A little help, please.....

Re: Lookup Field Advance Customization help

Posted: 2020-11-27 07:15
by sathukorala
category.png
category.png (22.61 KiB) Viewed 2313 times
This is the best way to do it if anybody is interested

Courtesy of pböttcher

Re: Lookup Field Advance Customization help

Posted: 2020-11-27 07:22
by jsetzer
(1)

Did you setup the tables and lookups correctly? Like this:

Countries
-id
-name

Cities
-id
-country_id (lookup cities name)
-name

If cities.country_id is a lookup to countries, the dependent dropdowns should work as expected.

(2)

You have to fill countries table first.

Then start filling cities table. On a new record in cities dv you can select a country from the dropdown.

(3)

Using data in a third table

Addresses
-id
-country_id (lookup countries name)
-city_id (lookup cities name, filter by country_id :!: )
-street
-...

If setup according to (1) and (2) is correct, there will be a checkbox "filter by country_id" when editing city_id field.

Whever you create a new address, after selecting a country, there will be cities related to the chosen country in cities-dropdown, only.

Re: Lookup Field Advance Customization help

Posted: 2020-11-27 07:23
by jsetzer
PS: I have seen that you have found the solution in the meantime while I was writing an answer.

:idea: Anyway, I hope my answer will help others configuring dependent lookups in the future.

PPS: please don't double post + email the same question

Re: Lookup Field Advance Customization help

Posted: 2020-11-27 14:52
by sathukorala
jsetzer wrote:
2020-11-27 07:22
(1)

Did you setup the tables and lookups correctly? Like this:

Countries
-id
-name

Cities
-id
-country_id (lookup cities name)
-name

If cities.country_id is a lookup to countries, the dependent dropdowns should work as expected.

(2)

You have to fill countries table first.

Then start filling cities table. On a new record in cities dv you can select a country from the dropdown.

(3)

Using data in a third table

Addresses
-id
-country_id (lookup countries name)
-city_id (lookup cities name, filter by country_id :!: )
-street
-...

If setup according to (1) and (2) is correct, there will be a checkbox "filter by country_id" when editing city_id field.

Whever you create a new address, after selecting a country, there will be cities related to the chosen country in cities-dropdown, only.
Thanks for the descriptive answer