How to add linked dropdown custom fields.

How to add linked dropdown custom fields.

I want to integrate the administrative subdivision of my country into Gibbon. I have two dropdown lists: the Regions list [Region1, Region2, Region3, Region4]; and the Departments list [Department1, Department2, Department3, Department4, Department5, Department6, Department7, Department8, Department9, Department10, Department11, Department12, Department13].

When I select Region1 from the Regions list, the Departments list should display only Department1, Department2, Department3, and Department4.

When I select Region2 from the Regions list, the Departments list should display only Department5, Department6.

When I select Region3 from the Regions list, the Departments list should display only Department7 and Department9.

When I select Region4 from the Regions list, the Departments list should display only Department8, Department10, Department11, and Department12.

How can I achieve this in Gibbon LMS?

Hi @optimium

Thank you for your question. In Gibbon, each department has a department type such as Administration, Learning Area. If you want to associate each department to a region you can create these regions as types and each department you create will be linked to a region assigned by you. You can add these regions to the types array list in code.

Hope that helps!!

Hi @Ali,
Thanks very much for reply. This is not exactly what i’m talking about. For exemple i have 2 dropdown lists. List1 [L10, L11, L12] and List2[L20,L21,L22,L23,L24,L25,L26]. When i select L10 in the List1, the List2 should show only L20 and L22; When i select L11 in the List1, the List2 should show only L21 and L24 and When i select L12 in the List1, the List2 should show only L25 and L26;

Hi @optimium

Sorry about misreading your initial question. Currently, gibbon does not support conditional dropdown lists in custom fields due to the complexities. One way to get around this could be to use some kind of prefix in each item in List1 and based on the prefix you can find the linked item in List2. I think, a more human centric solution would be able to handle this. Hope this is helpful!

Hi @Ali Thanks very much I apreciate

I tested this Option, I have installed the Module Query Builder.
I created 2 fields (Dropdown fields) and use Query to extract intems for each list :slight_smile:

for Field 1 : listing Departments (Field ID is 0046):
UPDATE gibbonCustomField
SET options = (
SELECT GROUP_CONCAT(name SEPARATOR ‘,’)
FROM gibbonDepartment – Table des départements
WHERE gibbonDepartmentID IN (
SELECT DISTINCT gibbonDepartmentID FROM gibbonCourse – Relie les départements aux cours
)
)
WHERE gibbonCustomFieldID = ‘0046’;

and for Field 2 : listing Courses associated to Departments (Field ID is 0047) :

UPDATE gibbonCustomField
SET options = (
SELECT GROUP_CONCAT(c.name SEPARATOR ‘,’)
FROM gibbonCourse c
JOIN gibbonDepartment d ON c.gibbonDepartmentID = d.gibbonDepartmentID
WHERE d.gibbonDepartmentID = (
SELECT c.gibbonDepartmentID
FROM gibbonCourse
WHERE gibbonCustomFieldID = ‘0046’
)
)
WHERE gibbonCustomFieldID = ‘0047’;

Now how can automaticaly update Field 2 (Courses) when I select an Item in List1 (Department)

Thanlks in advance.

Hi @optimium Looks like a solid approach to creating the options. Gibbon does not currently have an option to automatically select one dropdown based on another dropdown. However, by prefixing them, when people are using the dropdowns, this will aim to direct them to make the correct choice, but it won’t happen automatically. There is a lot more complexity required for us to make this automatic for custom fields, so it’s not something available at this time.