cancel
Showing results for 
Search instead for 
Did you mean: 

One Step Checkout Age Validation Field

One Step Checkout Age Validation Field

Hi guys,

 

How can I add the age validation field in one step checkout module? Is there an easy way?

 

Best,

 

Kay

1 REPLY 1

Re: One Step Checkout Age Validation Field

 It use dob.phtml widget.

 

Find customer/widget/dob.phtml and add it to your template from Base

 

Just add the following JS to the <script> tags

 

Varien.DOB.prototype.initialize = Varien.DOB.prototype.initialize.wrap(
    function(original, selector, required, format) {
        var el = $$(selector)[0];
        var container       = {};
        container.day       = Element.select(el, '.dob-day input')[0];
        container.month     = Element.select(el, '.dob-month input')[0];
        container.year      = Element.select(el, '.dob-year input')[0];
        container.full      = Element.select(el, '.dob-full input')[0];
        container.advice    = Element.select(el, '.validation-advice')[0];
        //we need this to make the object avaliable and enable wrapping of  validation method
        this.dateElement = new Varien.DateElement('container', container, required, format);
    }
);
Varien.DateElement.prototype.validate = Varien.DateElement.prototype.validate.wrap(
    function(original){
        if(original()){
            var today = new Date();
            if (today >= new Date(this.fullDate.getFullYear() + 18, this.fullDate.getMonth(), this.fullDate.getDate())) {
                return true;
            } else {
                this.advice.innerHTML = this.errorTextModifier(Translator.translate('You have to be at least 18 years old.'));
                this.advice.show();
                return false;
            }
        }
    }
);