1
0
mirror of synced 2024-11-25 23:06:02 +03:00

refactor!: Renamed validationMessages Formulario option to messages

This commit is contained in:
Zaytsev Kirill 2020-10-25 22:39:38 +03:00
parent ea93863a05
commit b1e126a149
3 changed files with 7 additions and 4 deletions

View File

@ -16,7 +16,7 @@ import {
interface FormularioOptions { interface FormularioOptions {
rules?: any; rules?: any;
validationMessages?: Record<string, Function>; messages?: Record<string, Function>;
} }
// noinspection JSUnusedGlobalSymbols // noinspection JSUnusedGlobalSymbols
@ -50,7 +50,7 @@ export default class Formulario {
extend (extendWith: FormularioOptions): Formulario { extend (extendWith: FormularioOptions): Formulario {
if (typeof extendWith === 'object') { if (typeof extendWith === 'object') {
this.rules = merge(this.rules, extendWith.rules || {}) this.rules = merge(this.rules, extendWith.rules || {})
this.messages = merge(this.messages, extendWith.validationMessages || {}) this.messages = merge(this.messages, extendWith.messages || {})
return this return this
} }
throw new Error(`[Formulario]: Formulario.extend() should be passed an object (was ${typeof extendWith})`) 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) return merge(this.rules, extendWith)
} }
/**
* Get validation messages by merging any passed in with global messages.
*/
getMessages (vm: Vue, extendWith: Record<string, Function>): Record<string, CreateMessageFn> { getMessages (vm: Vue, extendWith: Record<string, Function>): Record<string, CreateMessageFn> {
const raw = merge(this.messages || {}, extendWith) const raw = merge(this.messages || {}, extendWith)
const messages: Record<string, CreateMessageFn> = {} const messages: Record<string, CreateMessageFn> = {}

View File

@ -5,7 +5,7 @@ import Formulario from '@/index.ts'
import FormularioForm from '@/FormularioForm.vue' import FormularioForm from '@/FormularioForm.vue'
Vue.use(Formulario, { Vue.use(Formulario, {
validationMessages: { messages: {
required: () => 'required', required: () => 'required',
'in': () => 'in', 'in': () => 'in',
min: () => 'min', min: () => 'min',

View File

@ -10,7 +10,7 @@ const globalRule = jest.fn(() => { return false })
Vue.use(Formulario, { Vue.use(Formulario, {
rules: { globalRule }, rules: { globalRule },
validationMessages: { messages: {
required: () => 'required', required: () => 'required',
'in': () => 'in', 'in': () => 'in',
min: () => 'min', min: () => 'min',