Move js to form component
This commit is contained in:
parent
094550f99c
commit
334f3d8ed3
@ -6,10 +6,6 @@ export default {
|
|||||||
|
|
||||||
mixins: [FormMixin],
|
mixins: [FormMixin],
|
||||||
|
|
||||||
props: {
|
|
||||||
initialSelectedSection: String,
|
|
||||||
},
|
|
||||||
|
|
||||||
components: {
|
components: {
|
||||||
textinput,
|
textinput,
|
||||||
},
|
},
|
||||||
@ -17,37 +13,10 @@ export default {
|
|||||||
data: function() {
|
data: function() {
|
||||||
return {
|
return {
|
||||||
selectedSection: this.initialSelectedSection,
|
selectedSection: this.initialSelectedSection,
|
||||||
invalid: true,
|
|
||||||
fields: {},
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
created: function() {
|
|
||||||
this.$root.$on('field-mount', this.handleFieldMount)
|
|
||||||
},
|
|
||||||
|
|
||||||
mounted: function() {
|
|
||||||
this.$root.$on('field-change', this.handleChange)
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
handleFieldMount: function(event) {
|
|
||||||
const { name, optional } = event
|
|
||||||
this.fields[name] = optional
|
|
||||||
},
|
|
||||||
|
|
||||||
handleChange: function(event) {
|
|
||||||
const { name, valid, parent_uid } = event
|
|
||||||
this.fields[name] = valid
|
|
||||||
this.validateForm()
|
|
||||||
},
|
|
||||||
|
|
||||||
validateForm: function() {
|
|
||||||
const valid = !Object.values(this.fields).some(field => field === false)
|
|
||||||
this.invalid = !valid
|
|
||||||
return valid
|
|
||||||
},
|
|
||||||
|
|
||||||
toggleSection: function(sectionName) {
|
toggleSection: function(sectionName) {
|
||||||
if (this.selectedSection === sectionName) {
|
if (this.selectedSection === sectionName) {
|
||||||
this.selectedSection = null
|
this.selectedSection = null
|
||||||
@ -55,11 +24,5 @@ export default {
|
|||||||
this.selectedSection = sectionName
|
this.selectedSection = sectionName
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
handleSubmit: function(event) {
|
|
||||||
if (this.invalid) {
|
|
||||||
event.preventDefault()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,53 @@
|
|||||||
export default {
|
export default {
|
||||||
|
props: {
|
||||||
|
initialSelectedSection: String,
|
||||||
|
},
|
||||||
|
|
||||||
mounted: function() {
|
mounted: function() {
|
||||||
this.$root.$on('field-change', this.handleFieldChange)
|
this.$root.$on('field-change', this.handleFieldChange)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
created: function() {
|
||||||
|
this.$root.$on('field-mount', this.handleFieldMount)
|
||||||
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
handleFieldChange: function(event) {
|
handleFieldChange: function(event) {
|
||||||
const { value, name } = event
|
const { name, valid, parent_uid } = event
|
||||||
if (typeof this[name] !== undefined) {
|
if (typeof this[name] !== undefined) {
|
||||||
this[name] = value
|
this.fields[name] = valid
|
||||||
if (event['parent_uid'] === this._uid) {
|
|
||||||
|
if (parent_uid === this._uid) {
|
||||||
this.changed = true
|
this.changed = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.validateForm()
|
||||||
|
},
|
||||||
|
|
||||||
|
handleFieldMount: function(event) {
|
||||||
|
const { name, optional } = event
|
||||||
|
this.fields[name] = optional
|
||||||
|
},
|
||||||
|
|
||||||
|
validateForm: function() {
|
||||||
|
const valid = !Object.values(this.fields).some(field => field === false)
|
||||||
|
this.invalid = !valid
|
||||||
|
return valid
|
||||||
|
},
|
||||||
|
|
||||||
|
handleSubmit: function(event) {
|
||||||
|
if (this.invalid) {
|
||||||
|
event.preventDefault()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
data: function() {
|
data: function() {
|
||||||
return {
|
return {
|
||||||
changed: this.hasChanges,
|
changed: this.hasChanges,
|
||||||
|
fields: {},
|
||||||
|
invalid: true,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -9,6 +9,5 @@ if [ "$1" == "check" ]; then
|
|||||||
else
|
else
|
||||||
pipenv run black ${FILES_TO_FORMAT}
|
pipenv run black ${FILES_TO_FORMAT}
|
||||||
yarn run prettier --list-different --write "js/**/*.js" --config ./prettier.config.json
|
yarn run prettier --list-different --write "js/**/*.js" --config ./prettier.config.json
|
||||||
tt
|
|
||||||
yarn run prettier --list-different --write "styles/**/*.scss"
|
yarn run prettier --list-different --write "styles/**/*.scss"
|
||||||
fi
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user