cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jan Hoskens" ...@schaubroeck.be>
Subject Re: disabling widgets in CForms
Date Tue, 18 May 2004 09:09:59 GMT
Just noticed that I forgot the javascript. This has to be included (in your header, or include
it as woody-lib.js):

function woody_checkboxGroup(checkboxGroup, length){
for (var i = 0; i < length; i++) {
var gr = document.getElementById(checkboxGroup + "_items_" + i);
if (gr.style.display == "none")
{
gr.style.display = "block";
}
else
{
gr.style.display = "none";
}
} 
}

  ----- Original Message ----- 
  From: Jan Hoskens 
  To: users@cocoon.apache.org 
  Sent: Tuesday, May 18, 2004 9:02 AM
  Subject: Re: disabling widgets in CForms


  A while ago I created an extra template in my woody (cforms) to show/not show a group of
widgets if a checkbox is clicked. It may give you something to begin with:

  This template goes in your woody/cform stylesheet or create your own stylesheet and let
this stylesheet include the other woody/cform stylesheets

  <!--
      wi:group of type checkboxGroup: changes display settings to none resp. block if previous
was resp. block or none, thus flipping its display state
    -->
    <xsl:template match="wi:group[wi:styling/@type='checkboxGroup']">
      
       <xsl:variable name="value" select="wi:state/wi:*/wi:value"/>
      
   <!-- copy the "state-widget" attribute for use in for-each -->
      <xsl:variable name="state-widget" select="wi:state/wi:*/@id"/>

      <xsl:variable name="id" select="generate-id()"/>
          <xsl:apply-templates select="wi:label/node()"/>
    <xsl:apply-templates select="text()"/>
          <input type="checkbox" name="{$state-widget}" onchange=" woody_checkboxGroup('{$id}',
 {count(wi:items/*)})">
     <xsl:if test="$value = 'true'">
      <xsl:attribute name="checked">true</xsl:attribute>
     </xsl:if>
    </input>
          <xsl:if test="wi:items/*//wi:validation-message">
            <span style="color:red; font-weight: bold">&#160;!&#160;</span>
          </xsl:if>

        <!-- a div for each of the items -->
        <xsl:for-each select="wi:items/wi:*">
          <div id="{$id}_items_{position() - 1}">
     <xsl:if test="not($value = @displayWhen)">
      <xsl:attribute name="style">display:none</xsl:attribute>
     </xsl:if>
            <xsl:apply-templates select="."/>
          </div>
        </xsl:for-each>
    </xsl:template>

  Use this to show the checkbox (template):

  <wi:group>
      <wi:styling type="checkboxGroup"/>
      <wt:widget-label id="state"/>
      <wi:state>
        <wt:widget-label id="state"/>: <wt:widget id="state"/>
      </wi:state>
      <wi:items>
         <wi:group displayWhen="false">        
          <wi:items>
           Name:  <wt:widget id="name"/>
          </wi:items>
         </wi:group>
     </wi:items>
   </wi:group>

  definition:

    <wd:booleanfield id="state">
     <wd:label>Do you want to give your name?</wd:label>
    </wd:booleanfield>
    <wd:field id="name">
     <wd:datatype base="string"/>
    </wd:field>

  This should give you a textbox asking if you want to give your name, if checked a textfield
should appear.

  Note however, that this is just one way, you may accomplish the same by using javascript!

  Kind Regards,
  Jan

    ----- Original Message ----- 
    From: Jakob Schwendner 
    To: users@cocoon.apache.org 
    Sent: Tuesday, May 18, 2004 8:39 AM
    Subject: disabling widgets in CForms


    Hi,

    Is there a way to disable groups of widgets in CForms?

    My application:

    Payment:
    (x) Invoice
    ( ) Credit Card

    CC Number
    CC Expiry

    There is a choice between invoice or CC payment. In case the user
    selects Invoice payment the CC Number and CC expiry field should
    not get validated and at best not even be displayed. 
    Is there any preferred way to do this in CForms?

    thanks for any suggestions.


    Jakob Schwendner
    ------
    Public Image
    Creative Strategy & Production 
    for Print, Online & Broadcast Media
Mime
View raw message