Trouble getting select lists to cascade

Trouble getting select lists to cascade

bpitonibpitoni Posts: 21Questions: 7Answers: 2

I am trying to get the values in one select list to be dependent on another.

The two fields in my editor are:
{ label: "Building", name: "mc_data_table1.building", type: "select" }, { label: "Area", name: "mc_data_table1.area", type: "select", placeholder: "", placeholderDisabled: false },

And this is the dependent code:
editor1.dependent('mc_data_table1.building', function (val, data, callback) { $.ajax({ url: 'get_building_areas.php?bldg=' + val, dataType: 'json', success: function (json) { callback(json); } }); });

"get_building_areas.php" returns this json (from response body in IE developer):
{"options": {"area":["1st Floor","2nd Floor","3rd Floor","4th Floor","5th Floor","6th Floor","7th Floor","8th Floor","Ground"]}}

But the "area" select list remains blank!

Server side code is:
Field::inst( 'mc_data_table1.area' ) ->setFormatter('Format::ifEmpty', null),

Any help would be appreciated. Thank you!

This question has an accepted answers - jump to answer

Answers

  • bpitonibpitoni Posts: 21Questions: 7Answers: 2
    Answer ✓

    Simple fix:

    get_building_areas.php needs to return the table name with the field name.

    {"options": {"mc_data_table1.area": ["1st Floor", "2nd Floor", ...

    Hope this helps someone.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Thanks for posting back. Good to hear you've got it fixed.

    Allan

This discussion has been closed.