Skip to content

Commit f0c461c

Browse files
author
Dipak Sarkar
committed
[Fix] Overridding the default config for multiple component
1 parent cc86be3 commit f0c461c

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

docs/.vuepress/components/Example.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
:dark="false"
6262
dense
6363
outlined
64-
v-model="priceUnmasked"
64+
v-model.lazy="priceUnmasked"
6565
v-number="config"
6666
/>
6767
<div>Model value: <span class="text-bold">{{priceUnmasked}}</span></div>
@@ -95,13 +95,15 @@ export default {
9595
suffix: ' %',
9696
precision: 2,
9797
null_value: '',
98-
masked: false
98+
masked: false,
99+
reverseFill: false
99100
},
100101
reverseFill: 6789.10,
101102
configReverseFill: {
102103
decimal: ',',
103104
separator: '.',
104105
prefix: '$',
106+
suffix: '',
105107
precision: 2,
106108
null_value: '',
107109
reverseFill: true

src/core.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import NumberFormat from './number-format'
2-
import options from './options'
2+
// import options from './options'
33

4-
export const CONFIG_KEY = '__input-number-format__'
4+
export const CONFIG_KEY = '__input-facade__'
55

66
/**
77
* Creates a CustomEvent('input') with detail = { facade: true }
@@ -14,15 +14,18 @@ export function FacadeInputEvent() {
1414
detail: { facade: true }
1515
})
1616
}
17-
1817
/**
1918
* Transform an array or string config into an object
2019
*
21-
* @param {Object} config The mask config object
22-
* @param {Object} modifiers An object of modifier flags that can influence the masking process
20+
* @param {object} config The format config object
21+
* @param {object} modifiers An object of modifier flags that can influence the formating process
2322
*/
24-
export function normalizeConfig(config) {
25-
return Object.assign(options, config)
23+
export function normalizeConfig(config, modifiers) {
24+
if (Array.isArray(config) || typeof config === 'string') {
25+
config = { modifiers: config }
26+
}
27+
28+
return Object.assign(config || {}, modifiers)
2629
}
2730

2831
/**

src/directive.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import * as core from './core'
2+
import defaults from './options'
23

34
const CONFIG_KEY = core.CONFIG_KEY
45

56
export default {
67
bind: (el, { value }, vnode) => {
78
el = core.getInputElement(el)
8-
const config = core.normalizeConfig(value)
9+
const config = core.normalizeConfig(value, value)
910
el[CONFIG_KEY] = { config }
1011
// set initial value
1112
core.updateValue(el, vnode, { force: config.prefill })
@@ -43,7 +44,8 @@ export default {
4344
update: (el, { value, oldValue }, vnode) => {
4445
el = core.getInputElement(el)
4546
if (value !== oldValue) {
46-
el[CONFIG_KEY].config = core.normalizeConfig(value)
47+
const { config } = el[CONFIG_KEY]
48+
el[CONFIG_KEY].config = core.normalizeConfig(config, value)
4749
core.updateValue(el, vnode, { force: true })
4850
} else {
4951
core.updateValue(el, vnode)

0 commit comments

Comments
 (0)