From b1e126a149bed18faf0239d31ac033f995e4faac Mon Sep 17 00:00:00 2001 From: Zaytsev Kirill Date: Sun, 25 Oct 2020 22:39:38 +0300 Subject: [PATCH] refactor!: Renamed validationMessages Formulario option to messages --- src/Formulario.ts | 7 +++++-- test/unit/FormularioForm.test.js | 2 +- test/unit/FormularioInput.test.js | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Formulario.ts b/src/Formulario.ts index d482b77..0ba3718 100644 --- a/src/Formulario.ts +++ b/src/Formulario.ts @@ -16,7 +16,7 @@ import { interface FormularioOptions { rules?: any; - validationMessages?: Record; + messages?: Record; } // noinspection JSUnusedGlobalSymbols @@ -50,7 +50,7 @@ export default class Formulario { extend (extendWith: FormularioOptions): Formulario { if (typeof extendWith === 'object') { this.rules = merge(this.rules, extendWith.rules || {}) - this.messages = merge(this.messages, extendWith.validationMessages || {}) + this.messages = merge(this.messages, extendWith.messages || {}) return this } throw new Error(`[Formulario]: Formulario.extend() should be passed an object (was ${typeof extendWith})`) @@ -63,6 +63,9 @@ export default class Formulario { return merge(this.rules, extendWith) } + /** + * Get validation messages by merging any passed in with global messages. + */ getMessages (vm: Vue, extendWith: Record): Record { const raw = merge(this.messages || {}, extendWith) const messages: Record = {} diff --git a/test/unit/FormularioForm.test.js b/test/unit/FormularioForm.test.js index c453f96..9fa272b 100644 --- a/test/unit/FormularioForm.test.js +++ b/test/unit/FormularioForm.test.js @@ -5,7 +5,7 @@ import Formulario from '@/index.ts' import FormularioForm from '@/FormularioForm.vue' Vue.use(Formulario, { - validationMessages: { + messages: { required: () => 'required', 'in': () => 'in', min: () => 'min', diff --git a/test/unit/FormularioInput.test.js b/test/unit/FormularioInput.test.js index 2ec2ea1..4df4b5c 100644 --- a/test/unit/FormularioInput.test.js +++ b/test/unit/FormularioInput.test.js @@ -10,7 +10,7 @@ const globalRule = jest.fn(() => { return false }) Vue.use(Formulario, { rules: { globalRule }, - validationMessages: { + messages: { required: () => 'required', 'in': () => 'in', min: () => 'min',