2

Hi i have a problem about triggering component b-form-file.

<b-form-file ref="imageProfile"></b-form-file>

I try with this.$refs.imageProfile.click() not work. And i see not found click function on that element.

Thank You.

Komang Suryadana
  • 677
  • 1
  • 7
  • 17
  • Your `imageProfile` ref is a Vue component, not a standard element. It has no `click` method – Phil Jul 19 '18 at 06:17
  • What are you hoping to happen by calling `click()`? – Phil Jul 19 '18 at 06:21
  • I want to open dalog file. – Komang Suryadana Jul 19 '18 at 06:22
  • Possible duplicate of [In JavaScript can I make a "click" event fire programmatically for a file input element?](https://stackoverflow.com/questions/210643/in-javascript-can-i-make-a-click-event-fire-programmatically-for-a-file-input) – Phil Jul 19 '18 at 06:22
  • I wrote a slightly more detailed answer how to use here: https://stackoverflow.com/a/68959062/4720160 – Michael S Aug 28 '21 at 19:41

2 Answers2

10

The file form component of bootstrap-vue is a little different, for someone still get this problem, try this:

<b-form-file ref="pickImage" v-model="file" :state="Boolean(file)"></b-form-file>

this.$refs.pickImage.$el.childNodes[0].click();

hope this help !

Manh Nguyen
  • 429
  • 1
  • 11
  • 21
6

You need to trigger the click on the element, not the component.

Try this:

this.$refs.imageProfile.$el.click()

See Vue Docs at https://v2.vuejs.org/v2/api/#vm-el

tony19
  • 125,647
  • 18
  • 229
  • 307
Troy Morehouse
  • 5,320
  • 1
  • 27
  • 38