Hi Simone

Thanks for this...

The reason I asked this question is that we were trying this exact approach
(though not using a union), but since we are using Ajax, we have been
getting an error...

This is part of the definition for the form in question
It works correctly when we don't use Ajax, however
using Ajax we get the javascript alert error message:

"No element "life2" defined in document" after the item is selected.

(If kwdJointSingle is set to Single then only Life1 is enabled, otherwise
Life2 is also enabled)

Any ideas?

                <fd:field id="kwdSingleJoint">
                        <fd:label>Is this policy a Single Life or Joint Life 
policy?</fd:label>
                        <fd:datatype base="string"/>
                        <fd:initial-value>Single</fd:initial-value>
                        <fd:selection-list>
                                <fd:item value="Single"/>
                                <fd:item value="Joint"/>
                        </fd:selection-list>
                        <fd:on-value-changed>
                                <javascript>

                          var value = event.source.value;

                          var dob1Starwidget = 
event.source.lookupWidget("../life1/dob1Star");
                          dob1Starwidget.setValue(" * ");

                          var life2widget = 
event.source.lookupWidget("../life2");
                          var title2widget = 
event.source.lookupWidget("../life2/title2");
                          var firstName2widget = 
event.source.lookupWidget("../life2/firstName2");
                          var lastName2widget = 
event.source.lookupWidget("../life2/lastName2");

                          var gender2widget = 
event.source.lookupWidget("../life2/gender2");
                          var gender2Starwidget =
event.source.lookupWidget("../life2/gender2Star");
                          gender2Starwidget.setValue(" * ");

                          var dob2widget = 
event.source.lookupWidget("../life2/dob2");
                          var dob2Starwidget = 
event.source.lookupWidget("../life2/dob2Star");
                          dob2Starwidget.setValue(" * ");


                          if (value == "Joint")
                          {
                                
life2widget.setState(Packages.org.apache.cocoon.forms.formmodel.WidgetState.ACTIVE);
                                
gender2Starwidget.setState(Packages.org.apache.cocoon.forms.formmodel.WidgetState.ACTIVE);
                                
dob2Starwidget.setState(Packages.org.apache.cocoon.forms.formmodel.WidgetState.ACTIVE);
                          }
                          else
                          {

                                
life2widget.setState(Packages.org.apache.cocoon.forms.formmodel.WidgetState.DISABLED);
                                title2widget.setValue(null);
                                firstName2widget.setValue(null);
                                lastName2widget.setValue(null);
                                gender2widget.setValue(null);
                                
gender2Starwidget.setState(Packages.org.apache.cocoon.forms.formmodel.WidgetState.INVISIBLE);
                                dob2widget.setValue(null);
                                
dob2Starwidget.setState(Packages.org.apache.cocoon.forms.formmodel.WidgetState.INVISIBLE);
                          }

                        </javascript>
                        </fd:on-value-changed>
                </fd:field>

                ~
                ~
                ~

                <fd:group id="life1">
                        <fd:widgets>
                        ~
                        some fields defined
                        ~
                        </fd:widgets>
                </fd:group>
                <fd:group id="life2">
                        <fd:widgets>
                        ~
                        some other fields defined
                        ~
                        </fd:widgets>
                </fd:group>


Thanks again

Duncan

> Hi Duncan,
> you should put an fd:on-value-changed on the dropdown. From inside this
> listener, you can change the status of other widgets to DISABLED and
> have them appear disabled. It should work correctly also setting the
> state of a union.
>
> Simone
>
> Duncan McLean wrote:
>
>>Hi
>>
>>We have a situation where there is a dropdown list that contains one
>>of two options.
>>
>>On one option, we want a group of fields to display and the other set of
>>fields to display, but be in a disabled state.
>>The other option will still show the first set of fields, but the second
>>set of fields will now be enabled as well.
>>
>>Can anyone tell me whether it is possible to achieve this with a union -
>>as all the examples I have seen seem to conditionally show one set of
>>fields or another, not the scenario I have described.
>>
>>Thanks
>>
>>Duncan
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: [EMAIL PROTECTED]
>>For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>>
> --
> Simone Gianni
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to