fix select defaut value

This commit is contained in:
2020-09-12 08:52:20 +02:00
parent e91671a78f
commit 68cbc950f5
9 changed files with 41 additions and 33 deletions

View File

@@ -19,12 +19,11 @@ export default {
type: String,
required: true,
},
date: Date,
time: String,
required: {
type: Boolean,
default: false
},
selected: String,
errors: Object,
},
data: function () {
@@ -37,6 +36,12 @@ export default {
computed: {
hasError: function () {
return this.required && this.errors && this.errors[this.name] && this.errors[this.name].length > 0
},
date: function () {
return this.selected.split(' ')[0]
},
time: function () {
return this.selected.split(' ')[1]
}
},
methods: {

View File

@@ -1,10 +1,12 @@
<template>
<div class="relative mb-2">
<label v-if="label" :for="name" class="pb-2 font-bold text-xl ml-1">{{ label }}</label>
<select :name="name" v-for="option in options" :key="option.value" v-model="value" :class="'block w-full p-2 ' + errorClassObject()">
<option value="">----</option>
<option :value="option.value" v-if="selected === String(option.value)" selected>{{ option.label }}</option>
<option :value="option.value" v-else>{{ option.label }}</option>
<select :name="name"
v-model="selected"
:class="'block w-full p-2 ' + errorClassObject()">
<option v-for="option in options"
:key="option.value"
:value="option.value">{{ option.label }}</option>
</select>
<p class="text-red no-indent m-0" v-text="errorMessage()">Error Here</p>
</div>
@@ -21,18 +23,13 @@ export default {
required: true,
},
options: Array,
selected: String,
selected: Number,
required: {
type: Boolean,
default: false
},
errors: Object,
},
data: function () {
return {
value: ''
}
},
computed: {
hasError: function () {
return this.required && this.errors && this.errors[this.name] && this.errors[this.name].length > 0
@@ -56,9 +53,9 @@ export default {
}
},
watch: {
value: function () {
selected: function () {
this.clearErrors(this.name)
this.$emit('update:field', this.value)
this.$emit('update:field', this.selected)
}
}
}