Peter's blog
Woensdag, 15 november 2006ATK gets true test database supportReacties
Geeft reacties weer als
(Lineair | Samengevoegd)
Hello Peter!
Do you have some example for filter combo-boxes in cascade, I mean, I have countries, states, counties, and cities. I would like that if I select a country, next combo box shows only states of that select country, and etc. I had surfed and dive into the forum but I couldn't get it... So I'm so sad about it, because ATK seems to me a great framework. I really hope you can helpme, thanks in advance. Best regards Franz
It depends on where your data comes from. Are the countries, states and cities stored in the database? If so you can use multiple atkOneToManyRelations what you would normally do. However you have to register some dependencies between the different relations.
You can do this by calling $countryAttr->addDependee('state') etc. What this does is make sure that the state attribute gets refreshed once you select a different country. This means we are half way there. For the next part you need to add a filter on the state attribute that filters the states based on the selected country. You can can do this by calling $stateAttr->setDestinationFilter("state.country_id = '[country.id]'"); The same goes for the city selection. If you don't retrieve the countries or states from the database you can use the same dependency mechanism but you then have to override the edit methods for the state and city attributes. You can do this by creating a custom (sub-)class for the attributes or you can do this in the node by creating a method called _edit. Inside this method you have access to the current record and you can use that to filter the possible options. |
Blog










