form validate css

This commit is contained in:
Sebastian Frank 2017-08-29 21:12:27 +02:00
parent c6badd6a90
commit 901b918dbb
No known key found for this signature in database
GPG Key ID: DC2BC5C506EBF6F3
2 changed files with 20 additions and 12 deletions

View File

@ -8,9 +8,10 @@
:placeholder="item.placeholder" :placeholder="item.placeholder"
:type="item.type" :type="item.type"
v-model="formData[key]" v-model="formData[key]"
@validate="validateData(key)"> @validate="validateData(key)"
:invalid="formErrors[key]"
>
</my-input> </my-input>
<span class="error" v-if="formErrors[key]">required</span>
</div> </div>
<div> <div>
<button v-for="(b, i) in buttons" :key="i" @click.prevent="buttonClick(b.type)">{{ b.label }}</button> <button v-for="(b, i) in buttons" :key="i" @click.prevent="buttonClick(b.type)">{{ b.label }}</button>
@ -85,10 +86,4 @@ export default {
} }
} }
} }
</script> </script>
<style scoped>
.error {
color: red;
}
</style>

View File

@ -9,16 +9,28 @@
:name="name" :name="name"
:placeholder="placeholder" :placeholder="placeholder"
@blur="validate()" @blur="validate()"
@change="() => $emit('change', currentValue)"> @change="() => $emit('change', currentValue)"
:class="{invalid}"
>
<input type="password" v-else-if="type == 'password'" <input type="password" v-else-if="type == 'password'"
v-model="currentValue" v-model="currentValue"
:name="name" :name="name"
:placeholder="placeholder" :placeholder="placeholder"
@blur="validate()" @blur="validate()"
@change="() => $emit('change', currentValue)"> @change="() => $emit('change', currentValue)"
:class="{invalid}"
>
</div> </div>
</template> </template>
<style scoped>
.invalid {
background-color: #fcc;
}
</style>
<script> <script>
export default { export default {
name: "MyInput", name: "MyInput",
@ -28,7 +40,8 @@ export default {
'name', 'name',
'placeholder', 'placeholder',
'type', 'type',
'value' 'value',
'invalid'
], ],
data() { data() {
return { return {