You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Gary Larsen <ga...@envisn.com> on 2006/01/20 19:39:41 UTC

CForms hide button on load

Hi,

I'm stuck on something simple again.

I want to hide a button widget if the value of a boolean field is false on
form load. I'm trying using <fd:on-create>:

  <fd:form>
    <fd:on-create>
      <fd:javascript>
        var widgetStateInvisible =
org.apache.cocoon.forms.formmodel.WidgetState.INVISIBLE;
        var thisForm = event.source.form;

        if (!thisForm .lookupWidget("okToSync").getValue) {
            thisForm.lookupWidget("submitButton").state =
widgetStateInvisible;
        }
     </fd:javascript>
   </fd:on-create>

It appears that I'm able to get a reference to the "okToSync" wigdet (it's
not null) but the value is null, I'm assuming because it is not loaded yet.

Thanks for any help,
Gary


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


RE: CForms hide button on load

Posted by Gary Larsen <ga...@envisn.com>.
Excellent!  What I didn't get was on-value-changed is fired during
form_load.
 
Thank you for the help.
 
Gary



Here's how I've done that:

<fd:booleanfield id="useDefaultPort">
        <fd:label>Use default FTP Port (Leave checked if you are not
sure)</fd:label>
        <fd:initial-value>true</fd:initial-value> 
        <fd:on-value-changed>
            <javascript>
                <![CDATA[
                var parent = event.source.parent;
                var useDefaultPort =
parent.lookupWidget("useDefaultPort").getValue(); 
                                    
                if(useDefaultPort == "false") {
 
parent.lookupWidget("remotePort").setState(WidgetState.ACTIVE);
                } else { 
 
parent.lookupWidget("remotePort").setState(WidgetState.INVISIBLE);
                    parent.lookupWidget("remotePort").setValue(new
java.lang.Integer(21));
                } 
            ]]>
            </javascript>
        </fd:on-value-changed>
    </fd:booleanfield>
    <fd:field id="remotePort" required="true" state="invisible"> 
        <fd:datatype base="integer"/>
        <fd:label>Remote FTP Port</fd:label>
        <fd:validation>
            <fd:range min="1" max="65535"> 
                <fd:failmessage>Remote FTP Port must be a number between 1
and 65535</fd:failmessage>
            </fd:range>
        </fd:validation>
    </fd:field>

The only difference being I my boolean field needs to be false to show the
field. 

HTH



Re: CForms hide button on load

Posted by Archie Cowan <ar...@gmail.com>.
Here's how I've done that:

<fd:booleanfield id="useDefaultPort">
        <fd:label>Use default FTP Port (Leave checked if you are not
sure)</fd:label>
        <fd:initial-value>true</fd:initial-value>
        <fd:on-value-changed>
            <javascript>
                <![CDATA[
                var parent = event.source.parent;
                var useDefaultPort = parent.lookupWidget
("useDefaultPort").getValue();

                if(useDefaultPort == "false") {
                    parent.lookupWidget("remotePort").setState(
WidgetState.ACTIVE);
                } else {
                    parent.lookupWidget("remotePort").setState(
WidgetState.INVISIBLE);
                    parent.lookupWidget("remotePort").setValue(new
java.lang.Integer(21));
                }
            ]]>
            </javascript>
        </fd:on-value-changed>
    </fd:booleanfield>
    <fd:field id="remotePort" required="true" state="invisible">
        <fd:datatype base="integer"/>
        <fd:label>Remote FTP Port</fd:label>
        <fd:validation>
            <fd:range min="1" max="65535">
                <fd:failmessage>Remote FTP Port must be a number between 1
and 65535</fd:failmessage>
            </fd:range>
        </fd:validation>
    </fd:field>

The only difference being I my boolean field needs to be false to show the
field.

HTH

On 1/20/06, Gary Larsen <ga...@envisn.com> wrote:
>
> Hi,
>
> I'm stuck on something simple again.
>
> I want to hide a button widget if the value of a boolean field is false on
> form load. I'm trying using <fd:on-create>:
>
>   <fd:form>
>     <fd:on-create>
>       <fd:javascript>
>         var widgetStateInvisible =
> org.apache.cocoon.forms.formmodel.WidgetState.INVISIBLE;
>         var thisForm = event.source.form;
>
>         if (!thisForm .lookupWidget("okToSync").getValue) {
>             thisForm.lookupWidget("submitButton").state =
> widgetStateInvisible;
>         }
>      </fd:javascript>
>    </fd:on-create>
>
> It appears that I'm able to get a reference to the "okToSync" wigdet (it's
> not null) but the value is null, I'm assuming because it is not loaded
> yet.
>
> Thanks for any help,
> Gary
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>