cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "bart remmerie" <remme...@gmail.com>
Subject CForms-ajax : validation & on-value-changed event interference ??
Date Wed, 11 Apr 2007 21:00:09 GMT
I have a user-registration form, which checks if a username exists
using ajax (using the on-value-changed event), and displays it to the
user.
At the same time, I wanted to add validation to the field, doing
basically the same check, when the form is submitted.

What seems to happen each time the value is changed is the following sequence:
* validation of the field is executed, followed by
* the on-change-event code

BUT, when a username exists, the following seems to occur:

* validation is executed, and returns false => username is not valid
* on-change-event is executed, but the value of the field seems to be null
* the value remains in the widget

I can imagine that due to validation, the value is reset to null (not sure)
I have the following questions:
* Is my assumption correct: is the value reset due to the failing validation ?
* Why does the value still appear in the widget (on the screen) ?
* Why is validation carried out anyway ?

Please find the relevant code snippets below from register_model.xml.
Note that isNewUserNameValid(value) refers to a flowscript function
that checks if the username is still available.

<fd:field id="j_username" required="true">
   <fd:datatype base="string"/>
   <fd:label>username</fd:label>
   <fd:on-value-changed><!-- verify if the username is available -->
      <fd:javascript>
         var myValue=this.value;
         var userNameMessageWidget=widget.lookupWidget("../userNameMessage");
         if (value==null || value.length()==0){
            userNameMessageWidget.setValue('please enter a valid username');
         }
         else{
            if (!isNewUserNameValid(value)){
               userNameMessageWidget.setValue('the username '+value+'
is already in use, please select another username or login using the
login page');
            }
            else{
               userNameMessageWidget.setValue('this username is available');
            }
         }
      </fd:javascript>
   </fd:on-value-changed>

   <fd:validation>
      <fd:javascript>
         var success = true;
         if (!isNewUserNameValid(widget.value)){
            widget.setValidationError(new
Packages.org.apache.cocoon.forms.validation.ValidationError("this
username is currently in use", false));
            success = false;
         }
         return success;
      </fd:javascript>
   </fd:validation>
</fd:field>
<fd:field id="userNameMessage" state="output">
   <fd:datatype base="string"/>
</fd:field>

Best Regards,
Bart Remmerie

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


Mime
View raw message