cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jason Johnston" <>
Subject Re: Javascript State & Continuation
Date Thu, 15 Jun 2006 16:08:24 GMT
> I have a form binding a XML File with some repeaters, and for a nicest UI,
> I
> used some javascript to toggle hidden/shown state for some controls. I
> added
> a insert-row control, but when I use it, the page reloads itself, and the
> "javascript state" is not kept. So I have to switch again to show the part
> of the form.
> Is there a solution to keep the "javascript" on the continuation ?

That's an interesting problem.  Widget States are usually a good tool for
controlling visibility of widgets/groups, but it sounds like you want to
avoid hitting the server to show/hide a section.  So somehow you have to
find a way to get the state of your client-side DOM sent to the server
when the insert-row button is clicked, so it can be maintained and sent
back in the next response, and then have your client-side script use that
response value to re-initialize the correct state.

One way might be to create another field in your form that is rendered as
a hidden field, and then have your client-side javascript change the
hidden field's value when it toggles the hidden/shown state of your

<fd:field id="controlVisibility">
  <fd:datatype base="string"/>


<ft:widget id="myControlVisibility">
  <fi:styling type="hidden"/>


function toggleState() { //or whatever yours looks like...
  var myControl = ...
  var currentState =; = (currentState == "none" ? "" : "none");
  document.getElementById("myControlVisibility").value =
      (currentState == "none" ? "visible" : "hidden");

The last piece would be a window.onload handler (be careful because CForms
adds its own) that reads the hidden field's value and hides myControl if
its value is "hidden".

I hope this makes some sense, it's all in my head but it seems like it
should work.

Alternatively, if you choose to use the CForms AJAX rendering, this whole
issue goes away because the insert-row button would only reload the
repeater, not the whole page, so the state of your DOM would remain.

Hope that gives you a start,

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message