Refactor emitters
This commit is contained in:
parent
39975a0a31
commit
629dd674b9
@ -1,4 +1,4 @@
|
||||
import { emitFieldChange } from '../lib/emitters'
|
||||
import { emitEvent } from '../lib/emitters'
|
||||
|
||||
export default {
|
||||
name: 'checkboxinput',
|
||||
@ -9,7 +9,10 @@ export default {
|
||||
|
||||
methods: {
|
||||
onInput: function(e) {
|
||||
emitFieldChange(this, { value: e.target.checked, name: this.name })
|
||||
emitEvent('field-change', this, {
|
||||
value: e.target.checked,
|
||||
name: this.name,
|
||||
})
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import Vue from 'vue'
|
||||
import { getDaysInMonth } from 'date-fns'
|
||||
import { emitFieldChange } from '../lib/emitters'
|
||||
import { emitEvent } from '../lib/emitters'
|
||||
|
||||
var paddedNumber = function(number) {
|
||||
if ((number + '').length === 1) {
|
||||
@ -136,7 +136,7 @@ export default {
|
||||
|
||||
methods: {
|
||||
_emitChange: function(name, value, valid) {
|
||||
emitFieldChange(this, { value, name })
|
||||
emitEvent('field-change', this, { value, name })
|
||||
},
|
||||
},
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import optionsinput from '../components/options_input'
|
||||
import textinput from '../components/text_input'
|
||||
import { emitFieldChange } from '../lib/emitters'
|
||||
import { emitEvent } from '../lib/emitters'
|
||||
|
||||
export default {
|
||||
name: 'multicheckboxinput',
|
||||
@ -41,7 +41,10 @@ export default {
|
||||
|
||||
methods: {
|
||||
onInput: function(e) {
|
||||
emitFieldChange(this, { value: e.target.value, name: this.name })
|
||||
emitEvent('field-change', this, {
|
||||
value: e.target.value,
|
||||
name: this.name,
|
||||
})
|
||||
this.showError = false
|
||||
this.showValid = true
|
||||
},
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { emitFieldChange } from '../lib/emitters'
|
||||
import { emitEvent } from '../lib/emitters'
|
||||
|
||||
export default {
|
||||
name: 'optionsinput',
|
||||
@ -23,7 +23,10 @@ export default {
|
||||
|
||||
methods: {
|
||||
onInput: function(e) {
|
||||
emitFieldChange(this, { value: e.target.value, name: this.name })
|
||||
emitEvent('field-change', this, {
|
||||
value: e.target.value,
|
||||
name: this.name,
|
||||
})
|
||||
this.showError = false
|
||||
this.showValid = true
|
||||
},
|
||||
|
@ -1,7 +1,7 @@
|
||||
import MaskedInput, { conformToMask } from 'vue-text-mask'
|
||||
import inputValidations from '../lib/input_validations'
|
||||
import { formatDollars } from '../lib/dollars'
|
||||
import { emitFieldChange, emitFieldMount } from '../lib/emitters'
|
||||
import { emitEvent } from '../lib/emitters'
|
||||
|
||||
export default {
|
||||
name: 'textinput',
|
||||
@ -68,7 +68,7 @@ export default {
|
||||
},
|
||||
|
||||
created: function() {
|
||||
emitFieldMount(this, {
|
||||
emitEvent('field-mount', this, {
|
||||
optional: this.optional,
|
||||
name: this.name,
|
||||
})
|
||||
@ -126,7 +126,7 @@ export default {
|
||||
this.showValid = this.value != '' && valid
|
||||
|
||||
// Emit a change event
|
||||
emitFieldChange(this, {
|
||||
emitEvent('field-change', this, {
|
||||
value: this._rawValue(value),
|
||||
valid,
|
||||
name: this.name,
|
||||
|
@ -1,12 +1,5 @@
|
||||
export const emitFieldChange = (el, data) => {
|
||||
el.$root.$emit('field-change', {
|
||||
...data,
|
||||
parent_uid: el.$parent && el.$parent._uid,
|
||||
})
|
||||
}
|
||||
|
||||
export const emitFieldMount = (el, data) => {
|
||||
el.$root.$emit('field-mount', {
|
||||
export const emitEvent = (event_type, el, data) => {
|
||||
el.$root.$emit(event_type, {
|
||||
...data,
|
||||
parent_uid: el.$parent && el.$parent._uid,
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user