atst/js/components/options_input.js
leigh-mil bc0382834b Remove old field-mount and field-change emitters and listeners.
Replace FormMixin with new functionality.
2019-11-19 14:49:11 -05:00

48 lines
869 B
JavaScript

export default {
name: 'optionsinput',
props: {
name: String,
initialErrors: {
type: Array,
default: () => [],
},
initialValue: String,
watch: {
type: Boolean,
default: false,
},
optional: Boolean,
nullOption: {
type: String,
default: '',
},
},
data: function() {
const showError = (this.initialErrors && this.initialErrors.length) || false
return {
showError: showError,
showValid: false,
validationError: this.initialErrors.join(' '),
value: this.initialValue,
}
},
methods: {
onInput: function() {
this.$parent.$emit('field-change')
},
_isValid: function(value) {
return this.optional || value !== this.nullOption
},
},
computed: {
valid: function() {
return this._isValid(this.value)
},
},
}