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

Custom input file Field gives an error when upload a file #3522

Closed
2 of 4 tasks
paulorodrigues-mb opened this issue Oct 11, 2021 · 3 comments · Fixed by #3523
Closed
2 of 4 tasks

Custom input file Field gives an error when upload a file #3522

paulorodrigues-mb opened this issue Oct 11, 2021 · 3 comments · Fixed by #3523
Labels
📚 docs documentation related ❔ question More of an inquiry than an issue

Comments

@paulorodrigues-mb
Copy link

paulorodrigues-mb commented Oct 11, 2021

What happened?

When trying to customize a input file I use this:

<Field v-slot="{ field }" name="file">
  <input v-bind="field" type="file" />
</Field>

But some errors appears on console.

Reproduction steps

On demo link, just select a file and you will see the errors in console.

Version

Vue.js 3.x and vee-validate 4.x

What browsers are you seeing the problem on?

  • Firefox
  • Chrome
  • Safari
  • Microsoft Edge

Relevant log output

InvalidStateError
An attempt was made to use an object that is not, or is no longer, usable

Running local on chrome I can pause on unhandled exceptions and saw this message:

Failed to set the 'value' property on 'HTMLInputElement': This input element accepts a filename, which may only be programmatically set to the empty string



### Demo link

https://codesandbox.io/s/wild-river-xgptx

### Code of Conduct

- [X] I agree to follow this project's [Code of Conduct](CONDUCT.md)
@logaretm
Copy link
Owner

I wouldn't say this is a vee-validate issue as generally you wouldn't bind value prop to a type=file field.

I think this should be mentioned in the docs, generally you would do this instead:

    <Field name="file" v-slot="{ handleChange, value }">
      <input type="file" @change="handleChange" />
      <pre>{{ value }}</pre>
    </Field>

@bogdan12893
Copy link

bogdan12893 commented Dec 19, 2022

@logaretm can i use on input type file a custom method on change event? I can't validate the the selected file.

Field(name="file" v-slot="{ handleChange, value, validate }" rules="required")
    input(type="file" @change="handleFileChange($event, validate)")

I also need to preview the image file.

@vbullsey
Copy link

can i use a custom method?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 docs documentation related ❔ question More of an inquiry than an issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants