Skip to content

Instantly share code, notes, and snippets.

@giautm
Created April 12, 2016 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giautm/6bb0e006fa84dd133acf7d64c7365244 to your computer and use it in GitHub Desktop.
Save giautm/6bb0e006fa84dd133acf7d64c7365244 to your computer and use it in GitHub Desktop.
validate-date-range for magento
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