|
1958 | 1958 | badTelephone: 'You have not given a correct phone number',
|
1959 | 1959 | badSecurityAnswer: 'You have not given a correct answer to the security question',
|
1960 | 1960 | badDate: 'You have not given a correct date',
|
| 1961 | + badDateBefore: 'The minimum allowed date is ', |
| 1962 | + badDateAfter: 'The maximum allowed date is ', |
1961 | 1963 | lengthBadStart: 'The input value must be between ',
|
1962 | 1964 | lengthBadEnd: ' characters',
|
1963 | 1965 | lengthTooLongStart: 'The input value is longer than ',
|
|
2286 | 2288 |
|
2287 | 2289 | /*
|
2288 | 2290 | * Validate date
|
| 2291 | + * element attrs (optional, and both must use the same format as the field) |
| 2292 | + * data-validation-min-date |
| 2293 | + * data-validation-max-date |
2289 | 2294 | */
|
2290 | 2295 | $.formUtils.addValidator({
|
2291 | 2296 | name: 'date',
|
2292 |
| - validatorFunction: function (date, $el, conf) { |
| 2297 | + validatorFunction: function (date, $el, conf, lang) { |
2293 | 2298 | var dateFormat = $el.valAttr('format') || conf.dateFormat || 'yyyy-mm-dd',
|
2294 | 2299 | addMissingLeadingZeros = $el.valAttr('require-leading-zero') === 'false';
|
2295 |
| - return $.formUtils.parseDate(date, dateFormat, addMissingLeadingZeros) !== false; |
2296 |
| - }, |
2297 |
| - errorMessage: '', |
2298 |
| - errorMessageKey: 'badDate' |
| 2300 | + var dateParsed = $.formUtils.parseDate(date, dateFormat, addMissingLeadingZeros); |
| 2301 | + //checking date format |
| 2302 | + if (dateParsed === false){ |
| 2303 | + this.errorMessage = lang.badDate; |
| 2304 | + return false; |
| 2305 | + } |
| 2306 | + var dateInput = new Date(dateParsed[0], dateParsed[1] - 1, dateParsed[2]); |
| 2307 | + //checking min date, when informed |
| 2308 | + var dateMinValue = $el.valAttr('min-date'); |
| 2309 | + if (dateMinValue !== false && $.formUtils.parseDate(dateMinValue, dateFormat, addMissingLeadingZeros) !== false){ |
| 2310 | + var dateMinParsed = $.formUtils.parseDate(dateMinValue, dateFormat, addMissingLeadingZeros); |
| 2311 | + var dateMin = new Date(dateMinParsed[0], dateMinParsed[1] - 1, dateMinParsed[2]); |
| 2312 | + if (dateInput < dateMin){ |
| 2313 | + this.errorMessage = lang.badDateBefore + dateMinValue; |
| 2314 | + return false; |
| 2315 | + } |
| 2316 | + } |
| 2317 | + //checking max date, when informed |
| 2318 | + var dateMaxValue = $el.valAttr('max-date'); |
| 2319 | + if (dateMaxValue !== false && $.formUtils.parseDate(dateMaxValue, dateFormat, addMissingLeadingZeros) !== false){ |
| 2320 | + var dateMaxParsed = $.formUtils.parseDate(dateMaxValue, dateFormat, addMissingLeadingZeros); |
| 2321 | + var dateMax = new Date(dateMaxParsed[0], dateMaxParsed[1] - 1, dateMaxParsed[2]); |
| 2322 | + if (dateInput > dateMax){ |
| 2323 | + this.errorMessage = lang.badDateAfter + dateMaxValue; |
| 2324 | + return false; |
| 2325 | + } |
| 2326 | + } |
| 2327 | + return true; |
| 2328 | + } |
| 2329 | + //errorMessage: '', //setted above on the function |
| 2330 | + //errorMessageKey: 'badDate' //not used |
2299 | 2331 | });
|
2300 | 2332 |
|
2301 |
| - |
2302 | 2333 | /*
|
2303 | 2334 | * Validate group of checkboxes, validate qty required is checked
|
2304 | 2335 | * written by Steve Wasiura : http://stevewasiura.waztech.com
|
|
0 commit comments