-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
custom component validation #90
Comments
Ideally your validate component would be on the same level as the parent, e.g. <vue-form :state="formstate" @submit.prevent="onSubmit">
<validate>
<vue-form-input
required
v-model="user.firstName"
:type="'text'"
:label="'First Name'"
:name="'firstName'">
</vue-form-input>
</validate>
</vue-form> |
Thanks for the help! I was able to get this to work close to what I was looking for. Here's my updated code:
<vue-form :state="formstate" @submit.prevent="onSubmit">
<validate auto-label class="form-group" :class="fieldClassName(formstate.email)" :custom="{ email: emailValidator }">
<vue-form-input
required
v-model="user.email"
:formstate="formstate"
:type="'email'"
:label="'Email:'"
:name="'email'"
:messages="{ email: 'Please input a valid email', required: 'This field is required' }">
</vue-form-input>
</validate>
</vue-form>
<template>
<div>
<label>{{ label }}</label>
<input :value="value" @input="$emit('input', $event.target.value)" :type="type" :name="name" class="form-control" />
<field-messages :state="formstate" :name="name" show="$touched || $submitted">
<template>
<span class="glyphicon glyphicon-ok form-control-feedback"></span>
</template>
<template v-for="(message, key) in messages" :slot="key">
<span class="glyphicon glyphicon-remove form-control-feedback"></span>
<span class="has-error">{{ message }}</span>
</template>
</field-messages>
</div>
</template>
<script>
export default {
props: ['value', 'formstate', 'type', 'name', 'label', 'messages']
}
</script> The biggest downside is that I was hoping to keep all the validator functions and class functions in the |
Is there a way to get around the need to be on the same level? |
Hi, first of all, great project! So I tried to implement a custom component following your solution in #41, however validation does not seem to be working. Here's my code:
parent
component
Any idea what could be going on?
The text was updated successfully, but these errors were encountered: