This project is read-only.
2
Vote

Using Required fields: If child list is empty, subsequent parent selections won't re-populate children

description

I have used this script (latest version as of 08-August-2011) on required fields and it works unless we have a situation whereby a parent has no children.

Assuming we got Country and City lists and assume we have a country which has no cities associated to it.

When a country is selected which has no cities you get an empty list (correctly).
However, following that selection, when you try to select a country now which has cities, the city list stays empty.

This only happens when the city field (the child) is a required field.

The reason for this is that in the function "filterChildLookup" the code obtains the value of the first item before populating the child list. Like this:
if(CascadingDropdown.childLookup.Object.options[0].value == 0) startAt = 1;

The problem arrises when a previous child list had no items at all (required fields do NOT have the "none" default value) the list never was initialized and the object can't be queried for it's value.

To fix this I added a simple work around, checking the length of the object first.

I replaced the following line in function "function filterChildLookup(CascadingDropdown)":
if(CascadingDropdown.childLookup.Object.options[0].value == 0) startAt = 1;

With this:
if(CascadingDropdown.childLookup.Object.options.length > 0)
{
if(CascadingDropdown.childLookup.Object.options[0].value == 0) startAt = 1;
}


This worked and I'm now able to use the script with required and optional fields alike whereby the child list is always refreshed even if some parents have no children.
(This was never an issue with non required fields, only with required fields);

Can this fix (or similar) be included in the script?

comments