cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tobia <tobia.confo...@linux.it>
Subject Re: Cforms and Ajax validation workaround?
Date Thu, 15 Feb 2007 16:10:53 GMT
Gary Larsen wrote:
> I need to use tab styling with groups since there are so many widgets
> on the form.  The issue is that when a use submits the form, a
> validation error could occur on a non-active tab.  To the user the
> submit button is just not working.
> 
> Has anyone been able to come up with a solution to work around this
> issue?

I'm not sure if it's applicable to Ajax, but following our internal
usability guidelines we implemented this:


<xsl:template match="fi:form-template">
  <xsl:apply-imports/>
  <xsl:if test=".//fi:validation-message">
    <script type="text/javascript">
      <xsl:text>alert('The following data is missing or incorrect:\n</xsl:text>
      <xsl:for-each select=".//fi:validation-message">
        <xsl:text>\n</xsl:text>
        <xsl:value-of select="local:capitalize(../@id)"/>
        <xsl:if test="text()">
          <xsl:text> (</xsl:text>
          <xsl:value-of select="local:addslashes(normalize-space(.))"/>
          <xsl:text>)</xsl:text>
        </xsl:if>
      </xsl:for-each>
      <xsl:text>')</xsl:text>
    </script>
  </xsl:if>
</xsl:template>


It generates a javascript popup that informs the user about the fields
that need attention.  Here are the helper functions:


<func:function name="local:capitalize">
  <xsl:param name="s"/>
  <func:result select="concat(translate(substring($s, 1, 1), 
                                        'abcdefghijklmnopqrstuvwxyz', 
                                        'ABCDEFGHIJKLMNOPQRSTUVWXYZ'),
                              substring($s, 2))"/>
</func:function>

<func:function name="local:addslashes">
  <xsl:param name="s"/>
  <xsl:choose>
    <xsl:when test='contains($s, "&apos;")'>
      <func:result select='concat(substring-before($s, "&apos;"), 
                                  "\&apos;", 
                                  local:addslashes(substring-after($s, "&apos;")))'/>
    </xsl:when>
    <xsl:otherwise>
      <func:result select="$s"/>
    </xsl:otherwise>
  </xsl:choose>
</func:function>


HTH

Tobia

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


Mime
View raw message