refactor!: Renamed validationMessages Formulario option to messages
This commit is contained in:
parent
ea93863a05
commit
b1e126a149
@ -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> = {}
|
||||||
|
@ -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',
|
||||||
|
@ -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',
|
||||||
|
Loading…
Reference in New Issue
Block a user