Visual filtering for OptionGroup

Hello everyone!

I’m trying to filter the items of an OptionGroup based on the selection of a ComboBox. The problem is that I want to filter them only visually. Let me explain with a use case:

  • Think about a Country and Cities relationship
  • I have a ComboBox with countries, and an OptionGroup with cities
  • Depending on the city selected on the ComboBox, only the cities for that country should appear on the OptionGroup
  • When submitting the form, I want all selected cities to be sent with it, regardless the country selected on the ComboBox

Step by step:

  • Page loads with Spain selected in the country ComboBox
  • Madrid, Barcelona and Seville are shown in the OptionGroup
  • Select Madrid and Seville
  • Change the ComboBox to Finland
  • Only Helsinki is shown in the OptionGroup
  • Select Helsinki
  • Submit the form: I expect getValue() of the OptionGroup to return Madrid, Seville and Helsinki

How would you acomplish this behavior? I tried filtering the Container of the OptionGroup, but doing it that way causes the lost of the previously selected items.