cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Madu" <>
Subject Widget javascript validation problem
Date Wed, 05 Jul 2006 11:30:54 GMT
I am having an issue with a widget form validation under cocoon 2.1.8.
Basically what I have is a selection box with various credit card types,
(visa, matercard...) etc, and based on the card selected a check is done on
the credit card number field to make sure that the number of digits entered
corresponds correctly for that card type..for example 'visa' cards are 16
digits long. So I have the following xml code:

        var success = true;
        var creditCardType = widget.lookupWidget("credit");
        var accountNumberLength = widget.lookupWidget("account_no");

        try {
            //Determine the credit card type and then check that the length
            //of the credit card number is correct for the credit card type.

            if ( creditCardType.value == "visa" &amp;&amp;
accountNumberLength.value.length != 16) {
                account_no.setValidationError(new"Visa card
numbers are 16 chracters in length. Please re-enter the number.", false));
                success = false;

        } catch (e) {


        return success;


      <fd:field id="credit" required="true">
        <fd:label>Credit Card Type</fd:label>
        <fd:datatype base="string"/>
          <fd:item value="">
            <fd:label>Select your card type</fd:label>
          <fd:item value="visa">
          <fd:item value="mastercard">
            <fd:label>Master Card</fd:label>
          <fd:item value="american_express">
            <fd:label>American Express</fd:label>

      <fd:field id="account_no"  required="true">
          <fd:label>Account No</fd:label>
          <fd:datatype base="integer"/>


Now it seems that the  validation is not working because if I select 'visa'
and enter a card number of '1234', 4 digits long only, the validation should
fail the submit action but it does not. Can anyone see what I may be doing
wrong here?



View raw message