cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Fabrizio Sitzia" <>
Subject Ajax and IE empty textarea bugfix
Date Mon, 16 Jan 2006 16:28:11 GMT

While ajax'ifying one of my forms, I stumbled upon the following bug:

Empty textareas in a repeater are displayed incorrectly by Internet
Explorer after a round-trip to the server (for example after
adding/deleting a row, or when a validation error occurs!)

Instead of being empty, the textareas display a garbled mix of text and
html-tags occurring in the html document. Submission of the form usually
won't work afterwards...

Only Internet Explorer (IE6?) appears to be affected!
At least, I couldn't reproduce the bug on neither Firefox (on both Windows
and Mac OSX), nor the Safari (OSX) web browsers.

You can reproduce the bug as follows:

Create a form definition file with a repeater containing a text widget,
and a repeater action for adding new rows, as in the following snippet:

  <fd:form xmlns:fd="">
          <fd:repeater id="texts">
                  <fd:field id="text">
                      <fd:datatype base="string"/>
          <fd:repeater-action id="add_text" command="add-row"
              <fd:label>Add text</fd:label>

Create a jx template file to render the above form, as in the following

  <ft:form-template action="${}.kont" method="POST"
      <ft:repeater id="texts">
                      <ft:widget id="text">
                          <fi:styling type="textarea"/>
      <ft:widget id="add_text"><fi:styling type="submit"/></ft:widget>

Edit your sitemap to include the following:

  <!-- Flow controller -->
  <map:flow language="javascript">
      <map:script src="flow.js"/>

  <!-- Pipelines -->

  <!-- dispatch request to flow controller -->
  <map:match pattern="test">
      <map:call function="test_form"/>

  <!-- render form -->
  <map:match pattern="render_test">
      <map:generate type="jx" src="form.jx"/>
      <map:transform type="browser-update"/>
      <map:transform type="xslt" src="forms-styling.xsl"/>
      <map:select type="ajax-request">
          <map:when test="true">
              <map:serialize type="xml"/>
              <map:serialize type="html"/>

The following flow function only displays the form, nothing more:

  function test_form () {
      var form = new Form ("test.form");
      form.showForm ("render_test");

Invoke the 'test' pipeline. Click on the 'Add text' button for adding rows
to the repeater, and look what happens with IE. You really have to see it
to believe it!

Possible explanation:

After googling around a bit, I found similar bug descriptions concerning
empty textarea rendering problems: IE doesn't handle <textarea/> tags
correctly! It expects to find a closing textarea tag, and a (possibly
empty) value inbetween those tags...

Problem is, somewhere along the way (xslt transformer, xml serializer?)
our form rendering pipeline is turning empty textarea's into <textarea/>

Convert <textarea/> into <textarea></textarea>, and even the dumbest
web-browser is gonna be satisfied!

Possible bugfix:

I had a look into 'cocoon-ajax.js', and was positively astonished at how
compact it is!

Found it to be the best place for an IE-specific fix. After all, it is a
client-side JS library, and it already (sigh!) contains IE-specific stuff
( would have been something akin to a miracle, if no IE-specific code
were required in such a library. But then, Santa Claus doesn't exist

So I added two lines of code in the IE-specific portion of the
'importNode' method. Those lines replace any occurrence of '<textarea
attrs/>' tags with '<textarea attrs></textarea>' (svn diff enclosed below)
- keeping IE happy for whoever cares.

I'm posting this to the dev-list, as I don't like the idea of keeping a
patched 'cocoon-ajax.js' around for my webapps ( that's one more
pitfall to be aware of during my next Cocoon update!)
I'd therefore rather see some kind of fix in Cocoon's main trunk.

Best regards,

>svn diff cocoon-ajax.js
Index: cocoon-ajax.js
--- cocoon-ajax.js	(revision 369434)
+++ cocoon-ajax.js	(working copy)
@@ -70,6 +70,10 @@
         var div = targetDoc.createElement("DIV");
         var text = node.xml;

+		// Workaround for IE's <textarea/> bug
+		var tmatch = new RegExp('(<textarea.*?)\/>', 'img');
+		text = text.replace(tmatch, "$1></textarea>");
         // Extract scripts
         var match    = new RegExp(cocoon.ajax.DOMUtils.ScriptRegexp, 'img');

View raw message