On 2 March 2015 at 13:02, Erik de Hair <[email protected]> wrote: > Hi, > > I have 2 selectfields (A and B) where the elements of B depend on A, and I > have the following scenario: > > 1. Select an option at A > (choices for B are set now but no current selection at B) > 2. Select an option at B > 3. Select another option at A for which the current selection at B is not > valid > (Now the first option of the (changed) possible choices of B is selected > while I didn't select this option) > > The ReferencePanel has the following code: > > // called by setProviderAndCurrAndPending > private void resetIfCurrentNotInChoices(final > Select2Choice<ObjectAdapterMemento> > select2Field, final List<ObjectAdapterMemento> choiceMementos) { > ... > if(!curr.containedIn(choiceMementos)) { > if(!choiceMementos.isEmpty()) { > final ObjectAdapterMemento newAdapterMemento = > choiceMementos.get(0); > select2Field.getModel().setObject(newAdapterMemento); > getModel().setObject(newAdapterMemento.getObjectAdapter( > ConcurrencyChecking.NO_CHECK)); > } else { > select2Field.getModel().setObject(null); > getModel().setObject(null); > } > } > ... > } > > Is there any use of setting the selected option to the first item of the > choices? It seems a bit strange from the user's perspective. > > The rationale, IIRC, is that if the current value is not valid in the new set of choices --- if(!curr.containedIn(choiceMementos)) --- then we set the dependent choice to one of the valid set available as a convenience.
I suppose, strictly speaking, that this should only be done if the dependent parameter is mandatory; otherwise a user might want to leave it as null. > I can reset it in my code but maybe this scenario isn't desirable for any > Isis application. > > (Without trying it out for myself), I'm trying to think as to how you'd do that ... in the defaultNXxx() method, I am guessing? Cheers Dan > Erik >
