cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jan Hoskens">
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 ( == "none")
{ = "block";
{ = "none";

  ----- Original Message ----- 
  From: Jan Hoskens 
  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}',
     <xsl:if test="$value = 'true'">
      <xsl:attribute name="checked">true</xsl:attribute>
          <xsl:if test="wi:items/*//wi:validation-message">
            <span style="color:red; font-weight: bold">&#160;!&#160;</span>

        <!-- 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:apply-templates select="."/>

  Use this to show the checkbox (template):

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


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

  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,

    ----- Original Message ----- 
    From: Jakob Schwendner 
    Sent: Tuesday, May 18, 2004 8:39 AM
    Subject: disabling widgets in CForms


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

    My application:

    (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
View raw message