Hi,
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:

<fd:validation>
    <fd:_javascript_>
        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 Packages.org.apache.cocoon.forms.validation.ValidationError("Visa card numbers are 16 chracters in length. Please re-enter the number.", false));
                success = false;
            }

        } catch (e) {
               
        }

        return success;
    </fd:_javascript_>
</fd:validation>


<fd:widgets>

      <fd:field id="credit" required="true">
        <fd:label>Credit Card Type</fd:label>
        <fd:datatype base="string"/>
        <fd:selection-list>
          <fd:item value="">
            <fd:label>Select your card type</fd:label>
          </fd:item>
          <fd:item value="visa">
            <fd:label>Visa</fd:label>
          </fd:item>
          <fd:item value="mastercard">
            <fd:label>Master Card</fd:label>
          </fd:item>
          <fd:item value="american_express">
            <fd:label>American Express</fd:label>
          </fd:item>
        </fd:selection-list>
      </fd:field>
     
      <fd:field id="account_no"  required="true">
          <fd:label>Account No</fd:label>
          <fd:datatype base="integer"/>
     </fd:field>

</fd:widgets>

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?


regards

Andrew

Reply via email to