Tuesday, June 14, 2011

Dob day validation error for 08 in magento customer registration

Plz put the following script in the top of dob.phtml

< script type ="text/javascript">
<!--
Varien.DateElement = Class.create();Varien.DateElement.prototype {
    initialize
: function(typecontentrequiredformat{
        
if (type == 'id'{
            
// id prefix
            
this.day    = $(content 'day');
            
this.month  = $(content 'month');
            
this.year   = $(content 'year');
            
this.full   = $(content 'full');
            
this.advice = $(content 'advice');
        
else if (type == 'container'{
            
// content must be container with data
            
this.day    content.day;
            
this.month  content.month;
            
this.year   content.year;
            
this.full   content.full;
            
this.advice content.advice;
        
else {
            
return;
        
}

        this
.required required;
        
this.format   format;
        
        
this.day.addClassName('validate-custom');
        
this.day.validate this.validate.bind(this);
        
this.month.addClassName('validate-custom');
        
this.month.validate this.validate.bind(this);
        
this.year.addClassName('validate-custom');
        
this.year.validate this.validate.bind(this);

        
this.year.setAttribute('autocomplete','off');

        
this.advice.hide();
    
},
    
validate: function() {
        
var error false;
        if (
this.day.value=='' && this.month.value=='' && this.year.value==''{
            
if (this.required{
                error 
'<?php echo $this->__('Das Datum ist eine ben&ouml;tigte Angabe.');?>';
            
else {
                this
.full.value '';
            
}
        } 
else if (this.day.value=='' || this.month.value=='' || this.year.value==''{
            error 
'<?php echo $this->__('Please enter a valid full date.');?>';
        
else {
            
var date = new Date();
            if (
this.day.value<|| this.day.value>31{
                error 
'<?php echo $this->__('Please enter a valid day (1-31).');?>';
            
else if (this.month.value<|| this.month.value>12{
                error 
'<?php echo $this->__('Please enter a valid month (1-12).');?>';
            
else if (this.year.value<1900 || this.year.value>date.getFullYear()) {
                error 
'<?php echo $this->__('Please enter a valid year (1900-2010).');?>';
            
else {
                this
.full.value this.format.replace(/(%m|%b)/ithis.month.value).replace(/(%d|%e)/ithis.day.value).replace(/%y/ithis.year.value);
                var 
testFull this.month.value '/' this.day.value '/'this.year.value;
                var 
test = new Date(testFull);
                if (
isNaN(test)) {
                    error 
'Please enter a valid date.';
                
}
            }
        }

        
if (error !== false{
            
try {
                this
.advice.innerHTML Translator.translate(error);
            
}
            
catch (e{
                this
.advice.innerHTML error;
            
}
            this
.advice.show();
            return 
false;
        
}
        
        
// fixing elements class
        
this.day.removeClassName('validation-failed');
        
this.month.removeClassName('validation-failed');
        
this.year.removeClassName('validation-failed');
        
        
this.advice.hide();
        return 
true;
    
}
}
;
Varien.DOB = Class.create();Varien.DOB.prototype {
    initialize
: function(selectorrequiredformat{
        
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];
        
        new 
Varien.DateElement('container'containerrequiredformat);
    
}
}
;//--></script>



and enjoy............

1 comment:

  1. Hi and thank you for your post. It pointed me to the correct location of this problem.
    The problem isn't fount in magento itself.
    in /js/varien/js.js have a look at line 438. There you find
    [code]
    var error = false, day = parseInt(this.day.value) || 0, month = parseInt(this.month.value) || 0, year = parseInt(this.year.value) || 0;
    [/code]

    There you see the problem. With the help of this post:
    http://www.ventanazul.com/webzine/articles/issues-parseint-javascript
    you realise, that parseInt is not working correctly when you don't determine the base of the int conversion.

    So changing the above line to
    [code]
    var error = false, day = parseInt(this.day.value,10) || 0, month = parseInt(this.month.value,10) || 0, year = parseInt(this.year.value,10) || 0;
    [/code]

    would solve the issue;

    ReplyDelete