Skip to content

Commit 4bf9b2b

Browse files
authored
Merge pull request #555 from chantouchsek/bugfix/allow-add-msg-to-forceupdate
Bugfix/allow add msg to forceupdate
2 parents 387770f + 76b6dd6 commit 4bf9b2b

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"rimraf": "^3.0.2",
7373
"standard-version": "^9.3.1",
7474
"ts-jest": "^27.1.1",
75+
"ts-node": "^10.9.1",
7576
"typescript": "^4.5.3",
7677
"vue": "^2.6.14"
7778
},

src/__tests__/validator.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ describe('Validator', () => {
1414
validator.add('name', 'The name field is required.')
1515
expect(validator.any()).toBeTruthy()
1616
})
17+
test('Add an error with forceUpdate', () => {
18+
validator.add('name', 'The name field is required.', true)
19+
expect(validator.any()).toBeTruthy()
20+
})
1721
test('add error with missed attribute', () => {
18-
validator.add('name-3diidi', 'The name field is required.')
22+
validator.add('name-3', 'The name field is required.')
1923
expect(validator.any()).toBeTruthy()
2024
})
2125
test('Add an error message as string', () => {

src/core/Validator.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ class Validator {
1212
this.errors = errors
1313
}
1414

15-
add(attribute: string, message: string) {
15+
add(attribute: string, message: string, forceUpdate?: boolean) {
1616
if (this.missed(attribute)) {
1717
this.errors[attribute] = []
1818
}
1919
if (!this.errors[attribute].includes(message)) {
20+
this.errors[attribute].unshift(message)
21+
}
22+
if (forceUpdate) {
23+
this.errors[attribute] = []
2024
this.errors[attribute].push(message)
2125
}
2226
}

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11309,7 +11309,7 @@ ts-jest@^27.1.1:
1130911309
semver "7.x"
1131011310
yargs-parser "20.x"
1131111311

11312-
ts-node@^10.8.1:
11312+
ts-node@^10.8.1, ts-node@^10.9.1:
1131311313
version "10.9.1"
1131411314
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.9.1.tgz#e73de9102958af9e1f0b168a6ff320e25adcff4b"
1131511315
integrity sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==

0 commit comments

Comments
 (0)