From 5f613b3cd5c5991f238d472f9ac84479abf99bb8 Mon Sep 17 00:00:00 2001 From: Montana Date: Mon, 7 Jan 2019 13:58:20 -0500 Subject: [PATCH 1/5] Cleaning up checkbox code --- js/components/multi_checkbox_input.js | 16 +++++----- js/components/other_input.js | 29 ------------------- .../components/multi_checkbox_input.html | 2 +- 3 files changed, 8 insertions(+), 39 deletions(-) delete mode 100644 js/components/other_input.js diff --git a/js/components/multi_checkbox_input.js b/js/components/multi_checkbox_input.js index 7c0b822c..49fa1f07 100644 --- a/js/components/multi_checkbox_input.js +++ b/js/components/multi_checkbox_input.js @@ -1,4 +1,3 @@ -import otherinput from '../components/other_input' import optionsinput from '../components/options_input' import textinput from '../components/text_input' @@ -26,20 +25,14 @@ export default { data: function () { - const showError = (this.initialErrors && this.initialErrors.length) || false + const showError = (this.initialErrors && this.initialValue.length > 0) || false return { showError: showError, showValid: !showError && !!this.initialValue, validationError: this.initialErrors.join(' '), otherChecked: this.initialValue.includes("other") ? true : this.otherChecked, otherText: this.initialOtherValue, - selections: [] - } - }, - - mounted: function () { - for (let choice of this.initialValue) { - this.selections.push(choice) + selections: this.setSelection() } }, @@ -55,6 +48,11 @@ export default { otherToggle: function() { this.otherChecked = !this.otherChecked this.otherText = '' + }, + setSelection: function () { + for (let choice of this.initialValue) { + this.selections.push(choice) + } } } } diff --git a/js/components/other_input.js b/js/components/other_input.js deleted file mode 100644 index c2431b85..00000000 --- a/js/components/other_input.js +++ /dev/null @@ -1,29 +0,0 @@ -import FormMixin from '../mixins/form' -import textinput from '../components/text_input' - -export default { - name: 'otherinput', - - mixins: [FormMixin], - - components: { - textinput, - }, - - props: { - initialData: { - type: Array, - default: () => ({}) - } - }, - - data: function () { - const { - other = true - } = this.initialData - - return { - other - } - } -} diff --git a/templates/components/multi_checkbox_input.html b/templates/components/multi_checkbox_input.html index 3bd294c5..9a9543df 100644 --- a/templates/components/multi_checkbox_input.html +++ b/templates/components/multi_checkbox_input.html @@ -33,7 +33,7 @@
  • {% if choice[0] != 'other' %} - + {% else %} From d6910e85d426b736fe1192a92b27140065c82487 Mon Sep 17 00:00:00 2001 From: Montana Date: Tue, 8 Jan 2019 11:29:38 -0500 Subject: [PATCH 2/5] Fix vestigial code for deleted component --- js/components/multi_checkbox_input.js | 1 - js/index.js | 2 -- 2 files changed, 3 deletions(-) diff --git a/js/components/multi_checkbox_input.js b/js/components/multi_checkbox_input.js index 49fa1f07..14244459 100644 --- a/js/components/multi_checkbox_input.js +++ b/js/components/multi_checkbox_input.js @@ -5,7 +5,6 @@ export default { name: 'multicheckboxinput', components: { - otherinput, optionsinput, textinput, }, diff --git a/js/index.js b/js/index.js index 39271984..5bbee5d1 100644 --- a/js/index.js +++ b/js/index.js @@ -7,7 +7,6 @@ import VTooltip from 'v-tooltip' import optionsinput from './components/options_input' import multicheckboxinput from './components/multi_checkbox_input' -import otherinput from './components/other_input' import textinput from './components/text_input' import checkboxinput from './components/checkbox_input' import DetailsOfUse from './components/forms/details_of_use' @@ -40,7 +39,6 @@ const app = new Vue({ toggler, optionsinput, multicheckboxinput, - otherinput, textinput, checkboxinput, DetailsOfUse, From cef8861ab9b2bd6ff33f01a1edfed73d5994a0a7 Mon Sep 17 00:00:00 2001 From: Montana Date: Tue, 8 Jan 2019 11:38:01 -0500 Subject: [PATCH 3/5] Fix typo on multicheckboxinput vue component --- js/components/multi_checkbox_input.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/components/multi_checkbox_input.js b/js/components/multi_checkbox_input.js index 14244459..6235d4af 100644 --- a/js/components/multi_checkbox_input.js +++ b/js/components/multi_checkbox_input.js @@ -24,10 +24,10 @@ export default { data: function () { - const showError = (this.initialErrors && this.initialValue.length > 0) || false + const showError = (this.initialErrors && this.initialErrors.length) || false return { showError: showError, - showValid: !showError && !!this.initialValue, + showValid: !showError && this.initialValue.length > 0, validationError: this.initialErrors.join(' '), otherChecked: this.initialValue.includes("other") ? true : this.otherChecked, otherText: this.initialOtherValue, From dd33a23c479e0efce2542319cfb5264b71734d7d Mon Sep 17 00:00:00 2001 From: Montana Date: Wed, 9 Jan 2019 10:19:27 -0500 Subject: [PATCH 4/5] Fix off by one error --- js/components/multi_checkbox_input.js | 7 +------ templates/components/multi_checkbox_input.html | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/js/components/multi_checkbox_input.js b/js/components/multi_checkbox_input.js index 6235d4af..6ab3e050 100644 --- a/js/components/multi_checkbox_input.js +++ b/js/components/multi_checkbox_input.js @@ -31,7 +31,7 @@ export default { validationError: this.initialErrors.join(' '), otherChecked: this.initialValue.includes("other") ? true : this.otherChecked, otherText: this.initialOtherValue, - selections: this.setSelection() + selections: this.initialValue } }, @@ -48,10 +48,5 @@ export default { this.otherChecked = !this.otherChecked this.otherText = '' }, - setSelection: function () { - for (let choice of this.initialValue) { - this.selections.push(choice) - } - } } } diff --git a/templates/components/multi_checkbox_input.html b/templates/components/multi_checkbox_input.html index 9a9543df..cb9b37d2 100644 --- a/templates/components/multi_checkbox_input.html +++ b/templates/components/multi_checkbox_input.html @@ -33,7 +33,7 @@
  • {% if choice[0] != 'other' %} - + {% else %} From ac1df00730d2e2e76b0f132f9c63fadb654ea4d1 Mon Sep 17 00:00:00 2001 From: Montana Date: Wed, 9 Jan 2019 10:58:11 -0500 Subject: [PATCH 5/5] Use loop.index0 everywhere --- templates/components/multi_checkbox_input.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/components/multi_checkbox_input.html b/templates/components/multi_checkbox_input.html index cb9b37d2..ec8f666a 100644 --- a/templates/components/multi_checkbox_input.html +++ b/templates/components/multi_checkbox_input.html @@ -32,11 +32,11 @@ {% for choice in field.choices %}
  • {% if choice[0] != 'other' %} - + {% else %} - - + +