diff --git a/js/components/checkbox_input.js b/js/components/checkbox_input.js index 604dd355..6e646fa1 100644 --- a/js/components/checkbox_input.js +++ b/js/components/checkbox_input.js @@ -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, + }) }, }, } diff --git a/js/components/date_selector.js b/js/components/date_selector.js index df1142b1..0943bd0b 100644 --- a/js/components/date_selector.js +++ b/js/components/date_selector.js @@ -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 }) }, }, diff --git a/js/components/multi_checkbox_input.js b/js/components/multi_checkbox_input.js index 44a8c184..2be2d0fa 100644 --- a/js/components/multi_checkbox_input.js +++ b/js/components/multi_checkbox_input.js @@ -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 }, diff --git a/js/components/options_input.js b/js/components/options_input.js index 085212e5..a2ad1838 100644 --- a/js/components/options_input.js +++ b/js/components/options_input.js @@ -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 }, diff --git a/js/components/text_input.js b/js/components/text_input.js index 75c9d5f0..c34e6fd8 100644 --- a/js/components/text_input.js +++ b/js/components/text_input.js @@ -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, diff --git a/js/lib/emitters.js b/js/lib/emitters.js index c4cc3bf4..fa0567d7 100644 --- a/js/lib/emitters.js +++ b/js/lib/emitters.js @@ -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, })