Conditional dropdown behavior quirk

May 18, 2013 at 10:48 AM
Hi there.

I have an action with 3 parameters (A a, B a, C c)
C depends on B; B depends on A.
A is Bounded.
There is a conditional choices method for both B and C

I select A - B gets populated with the filtered items (A is selected. B is not selected, C is empty)
I select B - C gets populated with the filtered items (And B are selected. C is not selected)
I select C - (A, B, and C are all correctly selected)
Up to here it all is as expected.
But then, if I change the selection on A, B gets correctly repopulated and deselected, but C's items do not get removed and the old selection remains. C should get deselected and set to empty, because B is not currently selected.

However, If I change the selection of A a second time, then C correctly gets deselected and set to empty.
So a second change of A's selection produces the correct results, but not the first change.
Coordinator
May 20, 2013 at 8:50 AM
The framework is, I think, working correctly and consistently here. You could verify this by setting breakpoints on each of the three Choices methods.

When you change the selection of A, the ChoicesB and ChoicesC methods are being called. ChoicesB is called with the changed value of A, but ChoicesC will be called with the value of B as it exists in the form when A was changed. When both have been called, the page is then re-drawn, with the results you describe.

I think you can achieve the UI behaviour you want entirely through domain code (you could obviously do it using custom JavaScript), as follows. (N.B. I have never had to do a 'triple' selector like this myself, so this is supposition - but this is what I would be trying):

Leave ChoicesA and ChoicesB as is. Change ChoicesC so that it takes as input params the values of both A and B. Inside that method, check that the value for B is valid for the value of A (either the B value will 'know' its A, or you can delegate the problem to the ChoicesB method, which you can call internally). If B is valid for A then display the choices for C based on B (the current code), if not, return no choices at all.