Update TO form and nested components to emit directly to parent components instead of emitting from the root component

This commit is contained in:
leigh-mil
2019-11-07 15:02:20 -05:00
parent 92ce3420b6
commit c94570f83e
14 changed files with 131 additions and 79 deletions

View File

@@ -1,20 +1,8 @@
import { emitEvent } from '../lib/emitters'
import FormMixin from '../mixins/form'
import textinput from './text_input'
import optionsinput from './options_input'
import { buildUploader } from '../lib/upload'
export default {
name: 'uploadinput',
mixins: [FormMixin],
components: {
textinput,
optionsinput,
},
props: {
name: String,
filename: {
@@ -25,15 +13,8 @@ export default {
},
initialErrors: {
type: Boolean,
},
watch: {
type: Boolean,
default: false,
},
optional: {
type: Boolean,
default: true,
},
portfolioId: {
type: String,
},
@@ -51,12 +32,6 @@ export default {
},
created: async function() {
emitEvent('field-mount', this, {
optional: this.optional,
name: this.name,
valid: this.hasAttachment,
})
if (this.hasInitialData) {
this.downloadLink = await this.getDownloadLink(
this.filename,
@@ -93,12 +68,7 @@ export default {
this.changed = true
emitEvent('field-change', this, {
value: e.target.value,
name: this.name,
watch: this.watch,
valid: this.hasAttachment,
})
this.$parent.$emit('field-change')
},
removeAttachment: function(e) {
e.preventDefault()
@@ -110,11 +80,7 @@ export default {
this.clearErrors()
this.changed = true
emitEvent('field-change', this, {
value: e.target.value,
name: this.name,
watch: this.watch,
})
this.$parent.$emit('field-change')
},
clearErrors: function() {
this.uploadError = false
@@ -144,9 +110,6 @@ export default {
return this.attachment.split(/[\\/]/).pop()
}
},
hasAttachment: function() {
return !!this.attachment
},
hideInput: function() {
return this.hasInitialData && !this.changed
},
@@ -157,5 +120,8 @@ export default {
this.sizeError
)
},
valid: function() {
return !!this.attachment
},
},
}