Skip to content
This repository was archived by the owner on Dec 25, 2017. It is now read-only.

Commit b1add7d

Browse files
committed
⚡ improvement(errors): error messages order
Fixes #240
1 parent 3e916ef commit b1add7d

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/validator.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,8 @@ export default class Validator {
517517
}
518518
})
519519

520-
return empty(errors) ? undefined : errors
520+
return empty(errors) ? undefined : errors.sort((a, b) => {
521+
return (a.field < b.field) ? -1 : 1
522+
})
521523
}
522524
}

test/specs/errors.js

+9
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,15 @@ describe('errors', () => {
125125
assert(testMatches(group2Targets, vm.$validation.group2.errors) === 3)
126126
})
127127
})
128+
129+
describe('order', () => {
130+
it('should be ascending', () => {
131+
for (let i = 0; i < 6; i++) {
132+
const name = 'field' + (i + 1).toString()
133+
assert(vm.$validation.errors[i].field === name)
134+
}
135+
})
136+
})
128137
})
129138

130139

0 commit comments

Comments
 (0)