Skip to content
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

How to validate field via Vee-Validate? #286

Open
koddr opened this issue Jan 30, 2018 · 2 comments
Open

How to validate field via Vee-Validate? #286

koddr opened this issue Jan 30, 2018 · 2 comments
Labels

Comments

@koddr
Copy link

koddr commented Jan 30, 2018

Hello!

Some question here.. I use your component for upload one image in my form. All fields validated via Vee-Validate (simple reqired attribute). Can I validate vue-dropzone component too via Vee-Validate (latest version)? How?

Any examples are welcome! 👍
Thanks.

@psychonetic
Copy link

Hi,

you can do this easy. I have a component, which wraps the vue-dropzone.
See below:
Vue-Dropzone Wrapper:

<template>
<div class="input--group">
        <label class="input--group--label">{{label}}</label>
        <dropzone id="dropzone"
                  ref="dropzone"
                  :options="options"
                  :name="name"
                  @vdropzone-success="uploadDone"
                  @vdropzone-removed-file='remove'
                  :destroyDropzone="true"/>
        <p class="input--group--error" v-if="hasError">{{ error }}</p>
    </div>
</template>

Furthermore you should have a value prop. Whenever a file have been succesfully uploaded or removed, you should emit an input event.
In your parent component you can do this:

<v-uploader
                :url="uploadUrl"
                :mimes="uploader.mimes"
                :remove-url="removeUrl"
                v-model="form.file"
                v-validate="'required'"
                data-vv-name="file"
                data-vv-as="SEPA-Mandat"
                :has-error="hasError('file')"
                :error="collectErr('file')"
                label="File">
        </v-uploader>

Note: I have some custom methods inside vee-validator to handle also laravel form validation errors.
Here is a gist with complete code:
https://gist.github.com/psychonetic/9b01d2b1eb04b9654d8c2627a2b1bcb5

If you have any questions, feel free to ask :)

@rowanwins
Copy link
Owner

Thanks so much for sharing @psychonetic - I'll think I'll add this to the docs

@rowanwins rowanwins added the docs label Mar 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants