Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding validations for minimum and maximum dates #662

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/lang/ar.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
badTelephone: 'رقم الهاتف المدخل خاطئ',
badSecurityAnswer: 'لم يتم الإجابة عن سؤال الأمان',
badDate: 'تاريخ مدخل خاطئ',
badDateBefore: 'The minimum allowed date is ',
badDateAfter: 'The maximum allowed date is ',
lengthBadStart: 'القيمة المدخلة يجب أن تكون بين ',
lengthBadEnd: ' حروف',
lengthTooLongStart: 'القيمة المدخل أطول من ',
Expand Down
2 changes: 2 additions & 0 deletions src/lang/ca.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
badTelephone: 'El número de telèfon proporcionat no és vàlid',
badSecurityAnswer: 'La resposta a la seva pregunta de seguretat és incorrecte',
badDate: 'La data proporcionada no és vàlida',
badDateBefore: 'The minimum allowed date is ',
badDateAfter: 'The maximum allowed date is ',
lengthBadStart: 'La seva resposta s\'ha d\'incloure entre ',
lengthBadEnd: ' caràcters',
lengthTooLongStart: 'La seva resposta ha de ser menor a ',
Expand Down
2 changes: 2 additions & 0 deletions src/lang/cs.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
badTelephone: 'Neplatné telefonní číslo',
badSecurityAnswer: 'Chybná odpověď na bezpečnostní otázku',
badDate: 'Nesprávné datum',
badDateBefore: 'The minimum allowed date is ',
badDateAfter: 'The maximum allowed date is ',
lengthBadStart: 'Zadaná hodnota musí být v rozmezí ',
lengthBadEnd: ' znaků',
lengthTooLongStart: 'Zadaná hodnota je větší než ',
Expand Down
2 changes: 2 additions & 0 deletions src/lang/da.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
badCreditCard:'Det angivne kortnummer er ugyldigt',
badCustomVal: 'Den indtastede værdi er ugyldig',
badDate: 'Den angivne dato er ugyldig',
badDateBefore: 'The minimum allowed date is ',
badDateAfter: 'The maximum allowed date is ',
badDomain: 'Det angivne domæne er ugyldigt',
badEmail: 'Den angivne email adresse er ugyldig',
badInt: 'Det angivne tal er ugyldigt',
Expand Down
2 changes: 2 additions & 0 deletions src/lang/de.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
badTelephone: 'Sie haben keine richtige Telefonnummer eingetragen',
badSecurityAnswer: 'Sie haben die falsche Antwort auf die Sicherheitsfrage eingegeben',
badDate: 'Eingabe eines falschen Datums',
badDateBefore: 'The minimum allowed date is ',
badDateAfter: 'The maximum allowed date is ',
lengthBadStart: 'Der eingegebene Wert muss dazwischen sein ',
lengthBadEnd: '  Zeichen',
lengthTooLongStart: 'Der eingegebene Wert ist größer als ',
Expand Down
2 changes: 2 additions & 0 deletions src/lang/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
badTelephone: 'El número de teléfono proporcionado no es válido',
badSecurityAnswer: 'La respuesta a su pregunta de seguridad es incorrecta',
badDate: 'La fecha proporcionada no es válida',
badDateBefore: 'The minimum allowed date is ',
badDateAfter: 'The maximum allowed date is ',
lengthBadStart: 'Su respuesta debe incluir entre ',
lengthBadEnd: ' caracteres',
lengthTooLongStart: 'Su respuesta debe de ser menor a ',
Expand Down
2 changes: 2 additions & 0 deletions src/lang/fa.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
badTelephone: 'شماره تلفن وارد شده معتبر نیست',
badSecurityAnswer: 'شما به سوال امنیتی درست پاسخ نداده اید',
badDate: 'تاریخ درستی را وارد نکرده اید',
badDateBefore: 'The minimum allowed date is ',
badDateAfter: 'The maximum allowed date is ',
lengthBadStart: 'مقدار وارد شده باید ',
lengthBadEnd: ' حرف باشد.',
lengthTooLongStart: 'مقدار ورودی بیشتر از ',
Expand Down
2 changes: 2 additions & 0 deletions src/lang/fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
badTelephone: 'Vous n\'avez pas saisi un numéro de téléphone valide',
badSecurityAnswer: 'Vous avez saisi une mauvaise réponse à la question de sécurité',
badDate: 'Vous n\'avez pas saisi une date correcte',
badDateBefore: 'The minimum allowed date is ',
badDateAfter: 'The maximum allowed date is ',
lengthBadStart: 'Votre saisie doit comporter entre ',
lengthBadEnd: ' caractères',
lengthTooLongStart: 'Vous avez saisi une réponse qui est plus longue que ',
Expand Down
2 changes: 2 additions & 0 deletions src/lang/it.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
badTelephone: 'Il numero di telefono imputato non è valido',
badSecurityAnswer: 'La risposta alla domanda di sicurezza è errata',
badDate: 'La data scelta non è valida',
badDateBefore: 'The minimum allowed date is ',
badDateAfter: 'The maximum allowed date is ',
lengthBadStart: 'La sua risposta non può essere più lunga di ',
lengthBadEnd: ' caratteri',
lengthTooLongStart: 'La lunghezza della risposta deve essere minore di ',
Expand Down
2 changes: 2 additions & 0 deletions src/lang/ka.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
badTelephone: 'თქვენ მიუთითეთ არასწორი ტელეფონის ნომერი',
badSecurityAnswer: 'თქვენ გაეცით არასწორი პასუხი უსაფრთხოების კითხვას',
badDate: 'თქვენ მიუთითეთ არასწორი თარიღი',
badDateBefore: 'The minimum allowed date is ',
badDateAfter: 'The maximum allowed date is ',
lengthBadStart: 'ველის მნიშვნელობის სიგრძე უნდა იყოს ',
lengthBadEnd: ' შუალედში',
lengthTooLongStart: 'ველის მნიშვნელობის სიგრძე უნდა იყოს მაქსიმუმ ',
Expand Down
2 changes: 2 additions & 0 deletions src/lang/ko.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
badTelephone: '전화번호를 정확하게 입력하지 않았습니다.',
badSecurityAnswer: '보안 입력을 정확하게 입력하지 않았습니다.',
badDate: '날짜를 정확하게 입력하지 않았습니다.',
badDateBefore: 'The minimum allowed date is ',
badDateAfter: 'The maximum allowed date is ',
lengthBadStart: '입력 값은 ',
lengthBadEnd: ' 사이의 문자여야 합니다.',
lengthTooLongStart: '입력 값의 길이가 ',
Expand Down
2 changes: 2 additions & 0 deletions src/lang/nl.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
badCreditCard: 'Het creditcardnummer is onjuist',
badCustomVal: 'De ingevoerde waarde is onjuist',
badDate: 'U heeft niet de juiste datum aangegeven',
badDateBefore: 'The minimum allowed date is ',
badDateAfter: 'The maximum allowed date is ',
badDomain: 'Incorrect domein',
badEmail: 'U heeft een onjuist e-mailadres ingevoerd ',
badInt: 'De ingevoerde waarde was een onjuist getal',
Expand Down
2 changes: 2 additions & 0 deletions src/lang/no.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
badCreditCard: 'Kredittkortnummeret er ikke korrekt',
badCustomVal: 'Inntastingsverdien er ikke korrekt',
badDate: 'Du har ikke oppgitt en korrekt dato',
badDateBefore: 'The minimum allowed date is ',
badDateAfter: 'The maximum allowed date is ',
badDomain: 'Ukorrekt domeneverdi',
badEmail: 'Du har ikke oppgitt en korrekt e-postadresse',
badInt: 'Inntastingsverdien er ikke et korrekt tall',
Expand Down
2 changes: 2 additions & 0 deletions src/lang/pl.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
badTelephone: 'Wprowadzono niepoprawny numeru telefonu',
badSecurityAnswer: 'Nieprawidłowa odpowiedź na pytanie bezpieczeństwa',
badDate: 'Niepoprawna data',
badDateBefore: 'The minimum allowed date is ',
badDateAfter: 'The maximum allowed date is ',
lengthBadStart: 'Wprowadzona wartość musi być pomiędzy ',
lengthBadEnd: ' znaków',
lengthTooLongStart: 'Wprowadzona wartość jest większa niż ',
Expand Down
2 changes: 2 additions & 0 deletions src/lang/pt.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
badTelephone: 'O telefone digitado não é válido',
badSecurityAnswer: 'A pergunta de segurança não foi respondida corretamente',
badDate: 'A data digitada não é válida',
badDateBefore: 'A data mínima permitida é ',
badDateAfter: 'A data máxima permitida é ',
lengthBadStart: 'Sua resposta deve incluir entre ',
lengthBadEnd: ' caracteres',
lengthTooLongStart: 'Sua resposta tem mais que ',
Expand Down
2 changes: 2 additions & 0 deletions src/lang/ro.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
badTelephone: 'Numărul de telefon este incorect',
badSecurityAnswer: 'Răspuns incorect la întrebarea de siguran?ă',
badDate: 'Dară incorectă',
badDateBefore: 'The minimum allowed date is ',
badDateAfter: 'The maximum allowed date is ',
lengthBadStart: 'Valoarea introdusă trebuie să fie interval ',
lengthBadEnd: ' caractere',
lengthTooLongStart: 'Valoarea introdusă este mai mare decât ',
Expand Down
2 changes: 2 additions & 0 deletions src/lang/ru.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
badTelephone: 'Вы задали некорректный номер телефона',
badSecurityAnswer: 'Вы задали некорректный ответ на секретный вопрос',
badDate: 'Вы задали некорректную дату',
badDateBefore: 'The minimum allowed date is ',
badDateAfter: 'The maximum allowed date is ',
lengthBadStart: 'Значение должно быть в диапазоне',
lengthBadEnd: ' символов',
lengthTooLongStart: 'Значение длинее, чем ',
Expand Down
2 changes: 2 additions & 0 deletions src/lang/sv.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
badTelephone: 'Du har inte angett ett korrekt telefonnummer',
badSecurityAnswer: 'Du har angett fel svar på säkerhetsfrågan',
badDate: 'Du har anget ett felaktigt datum',
badDateBefore: 'The minimum allowed date is ',
badDateAfter: 'The maximum allowed date is ',
lengthBadStart: 'Ditt svar måste innehålla mellan ',
lengthBadEnd: ' tecken',
lengthTooLongStart: 'Du har angett ett svar som är längre än ',
Expand Down
2 changes: 2 additions & 0 deletions src/lang/tr.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
badTelephone: 'Geçersiz telefon numarası girdiniz',
badSecurityAnswer: 'Güvenlik sorusuna doğru cevap vermediniz',
badDate: 'Geçersiz tarih girdiniz',
badDateBefore: 'The minimum allowed date is ',
badDateAfter: 'The maximum allowed date is ',
lengthBadStart: 'Girilen değer ',
lengthBadEnd: ' karakter olmalıdır',
lengthTooLongStart: 'Girilen değer en fazla ',
Expand Down
2 changes: 2 additions & 0 deletions src/lang/vi.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
badTelephone: 'Số điện thoại chưa chính xác',
badSecurityAnswer: 'Câu hỏi bảo mật chưa chính xác',
badDate: 'Ngày tháng chưa chính xác',
badDateBefore: 'The minimum allowed date is ',
badDateAfter: 'The maximum allowed date is ',
lengthBadStart: 'Yêu cầu nhập từ ',
lengthBadEnd: ' ký tự',
lengthTooLongStart: 'Dữ liệu quá dài, yêu cầu ít hơn ',
Expand Down
40 changes: 35 additions & 5 deletions src/main/core-validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,16 +273,46 @@

/*
* Validate date
* element attrs (optional, and both must use the same format as the field)
* data-validation-min-date
* data-validation-max-date
*/
$.formUtils.addValidator({
name: 'date',
validatorFunction: function (date, $el, conf) {
validatorFunction: function (date, $el, conf, lang) {
var dateFormat = $el.valAttr('format') || conf.dateFormat || 'yyyy-mm-dd',
addMissingLeadingZeros = $el.valAttr('require-leading-zero') === 'false';
return $.formUtils.parseDate(date, dateFormat, addMissingLeadingZeros) !== false;
},
errorMessage: '',
errorMessageKey: 'badDate'
var dateParsed = $.formUtils.parseDate(date, dateFormat, addMissingLeadingZeros);
//checking date format
if (dateParsed === false){
this.errorMessage = lang.badDate;
return false;
}
var dateInput = new Date(dateParsed[0], dateParsed[1] - 1, dateParsed[2]);
//checking min date, when informed
var dateMinValue = $el.valAttr('min-date');
if (dateMinValue !== false && $.formUtils.parseDate(dateMinValue, dateFormat, addMissingLeadingZeros) !== false){
var dateMinParsed = $.formUtils.parseDate(dateMinValue, dateFormat, addMissingLeadingZeros);
var dateMin = new Date(dateMinParsed[0], dateMinParsed[1] - 1, dateMinParsed[2]);
if (dateInput < dateMin){
this.errorMessage = lang.badDateBefore + dateMinValue;
return false;
}
}
//checking max date, when informed
var dateMaxValue = $el.valAttr('max-date');
if (dateMaxValue !== false && $.formUtils.parseDate(dateMaxValue, dateFormat, addMissingLeadingZeros) !== false){
var dateMaxParsed = $.formUtils.parseDate(dateMaxValue, dateFormat, addMissingLeadingZeros);
var dateMax = new Date(dateMaxParsed[0], dateMaxParsed[1] - 1, dateMaxParsed[2]);
if (dateInput > dateMax){
this.errorMessage = lang.badDateAfter + dateMaxValue;
return false;
}
}
return true;
}
//errorMessage: '', //setted above on the function
//errorMessageKey: 'badDate' //not used
});


Expand Down
2 changes: 2 additions & 0 deletions src/main/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,8 @@
badTelephone: 'You have not given a correct phone number',
badSecurityAnswer: 'You have not given a correct answer to the security question',
badDate: 'You have not given a correct date',
badDateBefore: 'The minimum allowed date is ',
badDateAfter: 'The maximum allowed date is ',
lengthBadStart: 'The input value must be between ',
lengthBadEnd: ' characters',
lengthTooLongStart: 'The input value is longer than ',
Expand Down