Hi,
It is indeed a call to a flowscript function:
function isNewUserNameValid(value){
return getMyService().isValidNewUserName(value);
}
where getMyService() returns an instance of the service layer.
The method isValidNewUserName(String userName) returns a boolean indicating
if the username is found in the database.
2007/4/16, MML TML <[EMAIL PROTECTED]>:
I am trying to put validation in my CForms .. its a registration form but
I wanted to know wht you have been coded in "isNewUserNameValid(value)"
refers to a flowscript function.
Could you pls send me that script.
so that I can understand whole validation script.
Thanks
--kL
On 4/11/07, bart remmerie <[EMAIL PROTECTED]> wrote:
> 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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
Bart Remmerie