Created
April 12, 2016 14:04
-
-
Save giautm/6bb0e006fa84dd133acf7d64c7365244 to your computer and use it in GitHub Desktop.
validate-date-range for magento
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Validation.add('validate-date-range', '', function (value, elem) { | |
var match = elem.id.match(/^(.+)-(from|to)-(date|time)$/); | |
if (match) { | |
var fromDate = jQuery('#' + match[1] + '-from-date'); | |
if (match[3] === 'date') { | |
if (fromDate.val() > value) { | |
this.error = 'Giá trị cần phải lớn hơn hoặc bằng ' + fromDate.val(); | |
return false; | |
} | |
} else { | |
var toDate = jQuery('#' + match[1] + '-to-date'); | |
if (toDate.val() == fromDate.val()) { | |
var fromTime = jQuery('#' + match[1] + '-from-time'); | |
if (fromTime.val() > value) { | |
this.error = 'Giá trị cần phải lớn hơn hoặc bằng ' + fromTime.val(); | |
return false; | |
} | |
} | |
} | |
} | |
return true; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment