From 72d274c1f859ba5c10d8bfabb0017840a4ca7ced Mon Sep 17 00:00:00 2001 From: leigh-mil Date: Wed, 17 Jul 2019 10:08:20 -0400 Subject: [PATCH 1/4] Add canSave to the form mixin to toggle whether or not the Next button is disabled --- js/mixins/form.js | 12 ++++++++++++ templates/task_orders/builder_base.html | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/js/mixins/form.js b/js/mixins/form.js index 01f2f24f..ddb33607 100644 --- a/js/mixins/form.js +++ b/js/mixins/form.js @@ -44,6 +44,18 @@ export default { }, }, + computed: { + canSave: function() { + if (!this.invalid) { + return true + } else if (this.changed && !this.invalid) { + return true + } else { + return false + } + }, + }, + data: function() { return { changed: this.hasChanges, diff --git a/templates/task_orders/builder_base.html b/templates/task_orders/builder_base.html index e99aef9b..14c3eaa4 100644 --- a/templates/task_orders/builder_base.html +++ b/templates/task_orders/builder_base.html @@ -13,7 +13,7 @@ From 04d6672c0c80140a116dbecab9664f4a7bceb12f Mon Sep 17 00:00:00 2001 From: leigh-mil Date: Wed, 17 Jul 2019 10:09:00 -0400 Subject: [PATCH 2/4] Add mounted event emitter to checkbox input and send whether or not the field is valid on field-change --- js/components/checkbox_input.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/js/components/checkbox_input.js b/js/components/checkbox_input.js index db542fef..9236caf8 100644 --- a/js/components/checkbox_input.js +++ b/js/components/checkbox_input.js @@ -19,11 +19,20 @@ export default { } }, + created: function() { + emitEvent('field-mount', this, { + optional: this.optional, + name: this.name, + valid: this.isChecked, + }) + }, + methods: { onInput: function(e) { emitEvent('field-change', this, { value: e.target.checked, name: this.name, + valid: this.isChecked, }) }, }, From 90b057d0b2c58273ce8670da6bfe5368518f3d43 Mon Sep 17 00:00:00 2001 From: leigh-mil Date: Thu, 18 Jul 2019 14:57:50 -0400 Subject: [PATCH 3/4] Merge two sets of props in form mixin vue component --- js/mixins/form.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/js/mixins/form.js b/js/mixins/form.js index ddb33607..ab647621 100644 --- a/js/mixins/form.js +++ b/js/mixins/form.js @@ -1,6 +1,10 @@ export default { props: { initialSelectedSection: String, + hasChanges: { + type: Boolean, + default: false, + }, }, mounted: function() { @@ -63,11 +67,4 @@ export default { invalid: true, } }, - - props: { - hasChanges: { - type: Boolean, - default: false, - }, - }, } From 41f21ad830e2301b482de808e7b7540c7e992245 Mon Sep 17 00:00:00 2001 From: leigh-mil Date: Thu, 18 Jul 2019 14:59:56 -0400 Subject: [PATCH 4/4] Use variable to make canSave clearer --- js/mixins/form.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/js/mixins/form.js b/js/mixins/form.js index ab647621..7ba7629d 100644 --- a/js/mixins/form.js +++ b/js/mixins/form.js @@ -50,9 +50,11 @@ export default { computed: { canSave: function() { - if (!this.invalid) { + const formValid = !this.invalid + + if (formValid) { return true - } else if (this.changed && !this.invalid) { + } else if (this.changed && formValid) { return true } else { return false