Josep A. Frau wrote:

I have a text field with submit-on-change and a submit button on my form:

<fd:field id="P_CODPOS">
  <fi:styling submit-on-change="true"/>
  <fd:label>C.P.</fd:label>
  <fd:hint>Codi Postal</fd:hint>
  <fd:datatype base="string"/>
  <fd:on-value-changed>
    <javascript>
      ...
    </javascript>
  </fd:on-value-changed>
</fd:field>

<fd:submit id="B_MODIFICA_PERSONA" validate="true">
   <fd:label>Modificar dades</fd:label>
</fd:submit>

I get an alert with the message "onsubmit called twice!" when change the field value and, before leave the field, push the submit button.

The same occur if I change the value of P_CODPOS and press Enter key for submit the form.

When the field is a selection list this behavior can occur too. If I change value and push the submit button quickly but its more improbable the user make it voluntarily.

I have tested in Cocoon 2.1.7 with Firefox 1.0.6 and Explorer 6.0.

Is that the wished behavior?

In the forms-lib.js there is the function forms_onsubmit():

function forms_onsubmit() {
   if (forms_onsubmitHandlers == null) {
       alert("onsubmit called twice!");
   }

   for (var i = 0; i < forms_onsubmitHandlers.length; i++) {
       forms_onsubmitHandlers[i].forms_onsubmit();
   }
   // clear it
   forms_onsubmitHandlers = null;
}

This function is called each time a submit is fired. The first time is fired by the onchange event of P_CODPOS field and later the event of submit button.

In any case, I think that this behavior of the user is possible. Must the user see this message? It's safe just:

if (forms_onsubmitHandlers == null) {
    return;
   }

This don't show the alert, but follow the submit process.


This occurs because the click on the button triggers both the input's onchange and the form submit. I'll fix this.

Sylvain

--
Sylvain Wallez                        Anyware Technologies
http://people.apache.org/~sylvain     http://www.anyware-tech.com
Apache Software Foundation Member     Research & Technology Director

Reply via email to