1
0
mirror of synced 2024-11-22 05:16:05 +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 {
rules?: any;
validationMessages?: Record<string, Function>;
messages?: Record<string, Function>;
}
// 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<string, Function>): Record<string, CreateMessageFn> {
const raw = merge(this.messages || {}, extendWith)
const messages: Record<string, CreateMessageFn> = {}

View File

@ -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',

View File

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