Cleaning up checkbox code
This commit is contained in:
parent
7a7f8914c8
commit
5f613b3cd5
@ -1,4 +1,3 @@
|
|||||||
import otherinput from '../components/other_input'
|
|
||||||
import optionsinput from '../components/options_input'
|
import optionsinput from '../components/options_input'
|
||||||
import textinput from '../components/text_input'
|
import textinput from '../components/text_input'
|
||||||
|
|
||||||
@ -26,20 +25,14 @@ export default {
|
|||||||
|
|
||||||
|
|
||||||
data: function () {
|
data: function () {
|
||||||
const showError = (this.initialErrors && this.initialErrors.length) || false
|
const showError = (this.initialErrors && this.initialValue.length > 0) || false
|
||||||
return {
|
return {
|
||||||
showError: showError,
|
showError: showError,
|
||||||
showValid: !showError && !!this.initialValue,
|
showValid: !showError && !!this.initialValue,
|
||||||
validationError: this.initialErrors.join(' '),
|
validationError: this.initialErrors.join(' '),
|
||||||
otherChecked: this.initialValue.includes("other") ? true : this.otherChecked,
|
otherChecked: this.initialValue.includes("other") ? true : this.otherChecked,
|
||||||
otherText: this.initialOtherValue,
|
otherText: this.initialOtherValue,
|
||||||
selections: []
|
selections: this.setSelection()
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
mounted: function () {
|
|
||||||
for (let choice of this.initialValue) {
|
|
||||||
this.selections.push(choice)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -55,6 +48,11 @@ export default {
|
|||||||
otherToggle: function() {
|
otherToggle: function() {
|
||||||
this.otherChecked = !this.otherChecked
|
this.otherChecked = !this.otherChecked
|
||||||
this.otherText = ''
|
this.otherText = ''
|
||||||
|
},
|
||||||
|
setSelection: function () {
|
||||||
|
for (let choice of this.initialValue) {
|
||||||
|
this.selections.push(choice)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -33,7 +33,7 @@
|
|||||||
<li>
|
<li>
|
||||||
{% if choice[0] != 'other' %}
|
{% if choice[0] != 'other' %}
|
||||||
<input type='checkbox' name='{{ field.name }}' id='{{ field.name }}-{{ field.choices.index(choice) }}' value='{{ choice[0] }}' v-model="selections"/>
|
<input type='checkbox' name='{{ field.name }}' id='{{ field.name }}-{{ field.choices.index(choice) }}' value='{{ choice[0] }}' v-model="selections"/>
|
||||||
<label for='{{ field.name }}-{{ field.choices.index(choice) }}'>{{ choice[1] }}</label>
|
<label for='{{ field.name }}-{{ loop.index }}'>{{ choice[1] }}</label>
|
||||||
{% else %}
|
{% else %}
|
||||||
<input @click="otherToggle" type='checkbox' name='{{ field.name }}' id='{{ field.name }}-{{ field.choices.index(choice) }}' value='other' v-model="selections"/>
|
<input @click="otherToggle" type='checkbox' name='{{ field.name }}' id='{{ field.name }}-{{ field.choices.index(choice) }}' value='other' v-model="selections"/>
|
||||||
<label for='{{ field.name }}-{{ field.choices.index(choice) }}'>{{ choice[1] }}</label>
|
<label for='{{ field.name }}-{{ field.choices.index(choice) }}'>{{ choice[1] }}</label>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user