Skip to content

Commit af538b6

Browse files
gerjanvangeestdaKmoR
authored andcommitted
fix(validate): fix isDateDisabled validator
1 parent c47d9a2 commit af538b6

File tree

17 files changed

+36
-34
lines changed

17 files changed

+36
-34
lines changed

packages/validate/docs/ValidationSystem.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ By default, the validate system ships with the following validators:
5858
- isStringValidator
5959
- equalsLengthValidator, minLengthValidator, maxLengthValidator, minMaxLengthValidator
6060
- isNumberValidator, minNumberValidator, maxNumberValidator, minMaxNumberValidator
61-
- isDateValidator, minDateValidator, maxDateValidator, minMaxDateValidator
61+
- isDateValidator, minDateValidator, maxDateValidator, minMaxDateValidator, isDateDisabled
6262
- isEmailValidator
6363

64+
All validators return `true` if the required validity state is met.
65+
6466
As you can see, 'required' is placed in a string notation. It is the exception to the rule,
6567
since the implementation of required is context dependent: it will be different for a regular input
6668
than for a (multi)select and therefore not rely on one external function.

packages/validate/src/validators.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export const minMaxDateValidator = (...factoryParams) => [
8080
...factoryParams,
8181
];
8282

83-
export const isDateDisabled = (value, isDisabledFn) => isDisabledFn(value);
83+
export const isDateDisabled = (value, isDisabledFn) => isDate(value) && !isDisabledFn(value);
8484
export const isDateDisabledValidator = (...factoryParams) => [
8585
(...params) => ({ isDateDisabled: isDateDisabled(...params) }),
8686
...factoryParams,

packages/validate/test/validators.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ describe('LionValidate', () => {
131131
expect(isDate(4)).to.be.false;
132132
});
133133

134-
it('provides minDate() to allow only dates earlier then min', () => {
134+
it('provides minDate() to allow only dates after min', () => {
135135
expect(minDate(new Date('2018-02-03'), new Date('2018/02/02'))).to.be.true;
136136
expect(minDate(new Date('2018-02-01'), new Date('2018/02/02'))).to.be.false;
137137
});
@@ -152,8 +152,8 @@ describe('LionValidate', () => {
152152
});
153153

154154
it('provides isDateDisabled() to disable dates matching specified condition', () => {
155-
expect(isDateDisabled(new Date('2018/02/03'), d => d.getDate() === 3)).to.be.true;
156-
expect(isDateDisabled(new Date('2018/02/04'), d => d.getDate() === 3)).to.be.false;
155+
expect(isDateDisabled(new Date('2018/02/03'), d => d.getDate() === 3)).to.be.false;
156+
expect(isDateDisabled(new Date('2018/02/04'), d => d.getDate() === 3)).to.be.true;
157157
});
158158

159159
it('provides {isDate, minDate, maxDate, minMaxDate, isDateDisabled}Validator factory function for all types', () => {
@@ -180,7 +180,7 @@ describe('LionValidate', () => {
180180
'isDateDisabled',
181181
isDateDisabledValidator,
182182
new Date('2018/02/03'),
183-
d => d.getDate() !== 15,
183+
d => d.getDate() === 15,
184184
);
185185
});
186186
});

packages/validate/translations/bg.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default {
1515
maxDate: 'Моля, въведете {fieldName} преди {validatorParams, date, YYYYMMDD}.',
1616
minMaxDate:
1717
'Моля, въведете {fieldName} между {validatorParams.min, date, YYYYMMDD} и {validatorParams.max, date, YYYYMMDD}.',
18-
isDisabledDate: 'Тази дата не е на разположение, моля, изберете друга.',
18+
isDateDisabled: 'Тази дата не е на разположение, моля, изберете друга.',
1919
isEmail: 'Моля, въведете валиден {fieldName} с формат "name@example.com".',
2020
},
2121
warning: {
@@ -34,7 +34,7 @@ export default {
3434
maxDate: 'Моля, въведете {fieldName} преди {validatorParams, date, YYYYMMDD}.',
3535
minMaxDate:
3636
'Моля, въведете {fieldName} между {validatorParams.min, date, YYYYMMDD} и {validatorParams.max, date, YYYYMMDD}.',
37-
isDisabledDate: 'Тази дата не е на разположение, моля, изберете друга.',
37+
isDateDisabled: 'Тази дата не е на разположение, моля, изберете друга.',
3838
isEmail: 'Моля, въведете валиден {fieldName} с формат "name@example.com".',
3939
},
4040
success: {

packages/validate/translations/cs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default {
1515
maxDate: 'Zadejte {fieldName} před {validatorParams, date, YYYYMMDD}.',
1616
minMaxDate:
1717
'Zadejte {fieldName} od {validatorParams.min, date, YYYYMMDD} do {validatorParams.max, date, YYYYMMDD}.',
18-
isDisabledDate: 'Toto datum je nedostupné, vyberte jiné.',
18+
isDateDisabled: 'Toto datum je nedostupné, vyberte jiné.',
1919
isEmail: 'Zadejte platný {fieldName} ve formátu "name@example.com".',
2020
},
2121
warning: {
@@ -34,7 +34,7 @@ export default {
3434
maxDate: 'Zadejte {fieldName} před {validatorParams, date, YYYYMMDD}.',
3535
minMaxDate:
3636
'Zadejte {fieldName} od {validatorParams.min, date, YYYYMMDD} do {validatorParams.max, date, YYYYMMDD}.',
37-
isDisabledDate: 'Toto datum je nedostupné, vyberte jiné.',
37+
isDateDisabled: 'Toto datum je nedostupné, vyberte jiné.',
3838
isEmail: 'Zadejte platný {fieldName} ve formátu "name@example.com".',
3939
},
4040
success: {

packages/validate/translations/de.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default {
1919
'Geben Sie für {fieldName} einen Wert ein, der vor {validatorParams, date, YYYYMMDD} liegt.',
2020
minMaxDate:
2121
'Geben Sie für {fieldName} einen Wert zwischen {validatorParams.min, date, YYYYMMDD} und {validatorParams.max, date, YYYYMMDD} ein.',
22-
isDisabledDate: 'Dieses Datum ist nicht verfügbar, bitte wählen Sie ein anderes Datum.',
22+
isDateDisabled: 'Dieses Datum ist nicht verfügbar, bitte wählen Sie ein anderes Datum.',
2323
isEmail: 'Geben Sie einen gültige {fieldName} im Format „name@example.com“ ein.',
2424
},
2525
warning: {
@@ -42,7 +42,7 @@ export default {
4242
'Geben Sie für {fieldName} einen Wert ein, der vor {validatorParams, date, YYYYMMDD} liegt.',
4343
minMaxDate:
4444
'Geben Sie für {fieldName} einen Wert zwischen {validatorParams.min, date, YYYYMMDD} und {validatorParams.max, date, YYYYMMDD} ein.',
45-
isDisabledDate: 'Dieses Datum ist nicht verfügbar, bitte wählen Sie ein anderes Datum.',
45+
isDateDisabled: 'Dieses Datum ist nicht verfügbar, bitte wählen Sie ein anderes Datum.',
4646
isEmail: 'Geben Sie einen gültige {fieldName} im Format „name@example.com“ ein.',
4747
},
4848
success: {

packages/validate/translations/en.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default {
1616
maxDate: 'Please enter a(n) {fieldName} before {validatorParams, date, YYYYMMDD}.',
1717
minMaxDate:
1818
'Please enter a {fieldName} between {validatorParams.min, date, YYYYMMDD} and {validatorParams.max, date, YYYYMMDD}.',
19-
isDisabledDate: 'This date is unavailable, please choose another one.',
19+
isDateDisabled: 'This date is unavailable, please choose another one.',
2020
isEmail: 'Please enter a valid {fieldName} in the format "name@example.com".',
2121
},
2222
warning: {
@@ -36,7 +36,7 @@ export default {
3636
maxDate: 'Please enter a(n) {fieldName} before {validatorParams, date, YYYYMMDD}.',
3737
minMaxDate:
3838
'Please enter a {fieldName} between {validatorParams.min, date, YYYYMMDD} and {validatorParams.max, date, YYYYMMDD}.',
39-
isDisabledDate: 'This date is unavailable, please choose another one.',
39+
isDateDisabled: 'This date is unavailable, please choose another one.',
4040
isEmail: 'Please enter a valid {fieldName} in the format "name@example.com".',
4141
},
4242
success: {

packages/validate/translations/es.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default {
1717
maxDate: 'Introduzca un/a {fieldName} antes de {validatorParams, date, YYYYMMDD}.',
1818
minMaxDate:
1919
'Introduzca un/a {fieldName} entre {validatorParams.min, date, YYYYMMDD} y {validatorParams.max, date, YYYYMMDD}.',
20-
isDisabledDate: 'Esta fecha no está disponible. Elija otra.',
20+
isDateDisabled: 'Esta fecha no está disponible. Elija otra.',
2121
isEmail: 'Introduzca un/a {fieldName} válido/a con el formato "nombre@ejemplo.com".',
2222
},
2323
warning: {
@@ -38,7 +38,7 @@ export default {
3838
maxDate: 'Introduzca un/a {fieldName} antes de {validatorParams, date, YYYYMMDD}.',
3939
minMaxDate:
4040
'Introduzca un/a {fieldName} entre {validatorParams.min, date, YYYYMMDD} y {validatorParams.max, date, YYYYMMDD}.',
41-
isDisabledDate: 'Esta fecha no está disponible. Elija otra.',
41+
isDateDisabled: 'Esta fecha no está disponible. Elija otra.',
4242
isEmail: 'Introduzca un/a {fieldName} válido/a con el formato "nombre@ejemplo.com".',
4343
},
4444
success: {

packages/validate/translations/fr.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default {
1818
maxDate: 'Veuillez indiquer un(e) {fieldName} avant {validatorParams.max, date, YYYYMMDD}.',
1919
minMaxDate:
2020
'Veuillez indiquer un(e) {fieldName} entre {validatorParams.min, date, YYYYMMDD} et {validatorParams.max, date, YYYYMMDD}.',
21-
isDisabledDate: "Cette date n'est pas disponible, veuillez en choisir une autre.",
21+
isDateDisabled: "Cette date n'est pas disponible, veuillez en choisir une autre.",
2222
isEmail: 'Veuillez indiquer un(e) {fieldName} au format "nom@exemple.com".',
2323
},
2424
warning: {
@@ -40,7 +40,7 @@ export default {
4040
maxDate: 'Veuillez indiquer un(e) {fieldName} avant {validatorParams, date, YYYYMMDD}.',
4141
minMaxDate:
4242
'Veuillez indiquer un(e) {fieldName} entre {validatorParams.min, date, YYYYMMDD} et {validatorParams.max, date, YYYYMMDD}.',
43-
isDisabledDate: "Cette date n'est pas disponible, veuillez en choisir une autre.",
43+
isDateDisabled: "Cette date n'est pas disponible, veuillez en choisir une autre.",
4444
isEmail: 'Veuillez indiquer un(e) {fieldName} au format "nom@exemple.com".',
4545
},
4646
success: {

packages/validate/translations/hu.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default {
1616
maxDate: 'Adjon meg egy {validatorParams, date, YYYYMMDD} előtti {fieldName} értéket.',
1717
minMaxDate:
1818
'Adjon meg egy {validatorParams.min, date, YYYYMMDD} és {validatorParams.max, date, YYYYMMDD} közötti {fieldName} értéket.',
19-
isDisabledDate: 'Ez a dátum nem áll rendelkezésre, válasszon egy másikat.',
19+
isDateDisabled: 'Ez a dátum nem áll rendelkezésre, válasszon egy másikat.',
2020
isEmail:
2121
'Adjon meg egy érvényes {fieldName} értéket, a következő formátumban: „név@példa.com”.',
2222
},
@@ -37,7 +37,7 @@ export default {
3737
maxDate: 'Adjon meg egy {validatorParams, date, YYYYMMDD} előtti {fieldName} értéket.',
3838
minMaxDate:
3939
'Adjon meg egy {validatorParams.min, date, YYYYMMDD} és {validatorParams.max, date, YYYYMMDD} közötti {fieldName} értéket.',
40-
isDisabledDate: 'Ez a dátum nem áll rendelkezésre, válasszon egy másikat.',
40+
isDateDisabled: 'Ez a dátum nem áll rendelkezésre, válasszon egy másikat.',
4141
isEmail:
4242
'Adjon meg egy érvényes {fieldName} értéket, a következő formátumban: „név@példa.com”.',
4343
},

0 commit comments

Comments
 (0)