Reputation: 1344
I want to have a form in my checkout page that has an input for billing address and I have also a list of billing address. If the user has added any billing address from their account, it will listed on the checkout. Now if the user is on the checkout page then he/she will have two options, select a billing address from the list or add a new billing address. The "add" form has had spry validation added to it.
My problem was that if the user selects a billing address from the list the spry validation still occurs on the billing address form and the user can't submit the form. What I'd like to have happen is if the user clicks on the link "add the new billing", then the spry validations object will be created and the form is displayed and when the user clicks on the cancel button then the object is destroyed.
I have created an object when the user clicks on the link for the add form. Both the object & validation works perfectly.
UserAddressBookFullNameValid = new Spry.Widget.ValidationTextField("UserAddressBookFullNameValid", "none", {validateOn:["blur"]});
How to I destroy the object or remove the validation when the user clicks on the cancel button. I have tried some ways but it won't work. Examples:
delete UserAddressBookFullNameValid;
UserAddressBookFullNameValid = null;
So can anyone help me to do this or give me some another way?
Thanks
Upvotes: 1
Views: 1092
Reputation: 2368
To have this work, make sure UserAddressBookFullNameValid defined in your javascript.
var UserAddressBookFullNameValid;
Create the spry validation for the field as you do now. In the code for the cancel button put:
if (UserAddressBookFullNameValid != undefined) {
UserAddressBookFullNameValid.reset(); //Resets any validation css on the form
//(may not be necessary if hiding the inputs
UserAddressBookFullNameValid.destroy();
UserAddressBookFullNameValid= null;
}
I had a similar problem except I needed my field validated only if a checkbox was checked & it now works for me using this code.
Upvotes: 1