Solprovider Lenya Kongregate Registration for Free Flash Games and Chat with solprovider

Validation Popups do not use i18n

This article is about fixing Cocoon's Forms block to use i18n for error messages.

The Cocoon Forms block adds functionality for processing Forms. Just copy the cocoon-2.1.6-src/cocoon-2.1.6/src/blocks/forms/samples/resources directory inside Lenya. I recommend apache-lenya-1.2.2/build/lenya/webapp/lenya/resources/forms. It changes validation messages from displaying text to displaying an exclamation mark as a link to the message. That is a really bad interface decision, but I left it. There is a bug in that code so the error messages are not processed by i18n. This is the fix:

FILE: forms-field-styling.xsl
ADD:
xmlns:i18n="http://apache.org/cocoon/i18n/2.1"
to the xsl:stylesheet tag to avoid the error:
The prefix "i18n" for element "i18n:text" is not bound.

FIND:
<xsl:template match="fi:validation-message">
<a href="#" class="forms-validation-message" onclick="alert('{normalize-space(.)}');return false;">&#160;!&#160;</a>
</xsl:template>


REPLACE WITH:
<xsl:template match="fi:validation-message">
<SCRIPT>valmsg<xsl:number level="any"/> = "<i18n:text><xsl:value-of select="normalize-space(.)"/></i18n:text>"; </SCRIPT>
<xsl:element name="a">
<xsl:attribute name="href">javascript:alert(valmsg<xsl:number level="any"/>);</xsl:attribute>
<xsl:attribute name="class">forms-validation-message</xsl:attribute>
&#160;!&#160;
</xsl:element>
</xsl:template>


<< i18n MessagesXMAPs and XML >>

Contact Solprovider
Paul Ercolino