Cascading Selects in Form

Brendon McCarthy asked on August 20, 2014 19:45

Hi. I have two custom fields in a form, ProductDropDownList and PlatformMultipleChoice. Both get data from 2 Custom Tables:

Table_Product [ProductName,CompanyName] - all fields type=text Table_Product_Platform [PlatformName,ProductName] - all fields type=text

On the form, the Platform control needs to be filtered based upon the selection in the Product control. Cascading selects is a very common UI method, but I'm not seeing anything built into Kentico to do this?!

I've referenced http://stackoverflow.com/questions/15783025/cascading-dropdown-list-for-custom-field-in-kentico-cms, but not able to get the macro set correctly on the Platform field.

SELECT PlatformName, PlatformName FROM Table_Product_Platform T WHERE T.ProductName = '{% EditedObject.GetValue("ProductDropDownList") #%}'

Recent Answers


Brenden Kehren answered on August 20, 2014 20:35

What version are you running. Have you turned on debugging to see what is rendered or executed?

0 votesVote for this answer Mark as a Correct answer

Brendon McCarthy answered on August 20, 2014 21:52

Kentico 8. With that SQL query, the following SQL is executed according to the debugger:

SELECT PlatformName, PlatformName FROM Table_Product_Platform T WHERE T.ProductName = ''

So it appears the macro is finding no value for ProductDropDownList on load

0 votesVote for this answer Mark as a Correct answer

Brendon McCarthy answered on August 20, 2014 22:00

The macro evaluated to null in the logs: EditedObject.GetValue("ProductDropDownList") null The question might be how to get the value of the ProductDropDownList after it has been loaded or refreshed.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on August 21, 2014 04:10

I was able to create a form with 2 custom tables providing values for 2 fields in the form which are dropdowns. The custom tables were "group" and "sub group". Sub group has a parent group field in it. So when you create a sub group you select a parent.

In the form the my fields are as follows: Product, GroupID, SubGroupID.

GroupID is a dropdown field with a select statement below and has the "Has depending fields" box checked.

SELECT ITEMID AS Value, GroupName AS Name FROM customtable_MyTestGroups ORDER BY GroupName

SubGroupID is a dropdown field with a select statement below and has the "Depends on another field" box checked.

SELECT ItemID As Value, SubGroupName AS Name FROM customtable_MyTestSubGroup WHERE ParentGroup = {% GroupID @%} ORDER BY SubGroupName

When I create a new form record and select a different group, the sub group populates with correct items.

0 votesVote for this answer Mark as a Correct answer

Brendon McCarthy answered on August 21, 2014 20:20

That syntax works well, for the first load of the form. The first item in Group is selected and the Subgroups for first item appear. On change of Group though, the Subgroups do not change. The "Depends on another field" (Subgroup) and "Has depending fields" (Group) boxes are both checked. The page does a refresh, but no changes to the Subgroups.

Created a new form with just these values, same effect, both using form on page or using "New record" option in the Form editor.

0 votesVote for this answer Mark as a Correct answer

Brendon McCarthy answered on August 21, 2014 20:32

This is odd. If there are no Subgroups for the first value, onChange the Subgroup will update correctly with the proper subgroups for the selected Group. After the Subgroup is populated though, it will no longer update onChange.

For example:

Group1 > No subgroups. Group2 > Sub1, Sub2. Group3 > No subgroups. Group4 > Sub3, Sub4.

On form load, no data in Subgroup.

Scenario 1: Initial Group 1 = no data Select Group 4 = Sub3, Sub4 Select Group 2 = still Sub3, Sub4

Scenario 2: Initial Group 1 = no data Select Group 3 = no data Select Group 2 = Sub1, Sub2 Select Group 4 = still Sub1, Sub2

You can repeat in any number of patterns, after Subgroup has its first data set (not null), it does not change on future onchange/select events.

0 votesVote for this answer Mark as a Correct answer

Olivier Cozette answered on August 14, 2015 14:37

Brendon, did you come up with any solution? I'm having a similar issue here.

Thanks.

Juan

0 votesVote for this answer Mark as a Correct answer

Suman Layek answered on May 20, 2016 12:52 (last edited on December 10, 2019 02:30)

I am looking for the same solution so can you please let us know if the below is possible with Custom Table New Item Form. Where I have tried to create cascading feature to the form control where I have used two dropdown form controls with "Has Dependent Field and Depends on another Field" relation and set "SQL Query" as data source. The SubCategory SQL Query needs to be build with ParentCategory dropdown value. So can we use the below SQL Code with Macro to populate Sub Category ?

        SELECT ItemID, SubCategoryName FROM SubCategoryTable 
        WHERE ParentCategoryID= {%EditedObject.CategoryID|(identity)GlobalAdministrator%}
0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.