vue-form-wizard icon indicating copy to clipboard operation
vue-form-wizard copied to clipboard

Unable to focus on any text fields

Open lclyman opened this issue 6 years ago • 4 comments

There doesn't seem to be any way to focus on any input fields in form-wizard. I've tried autofocus on individual text inputs as well as a Vue directive that automatically places the focus on the element.

I've also directed the focus to the first text input in the mounted hook via document.getElementById('element name').focus() with no luck.

It would be great if this could be addressed..

Thanks

lclyman avatar Oct 31 '18 16:10 lclyman

I did this...

<form-wizard @on-change="tabChanged">
...
tabChanged(oldIndex, newIndex) {
  switch (newIndex) {
	  case 0:
		  this.$refs.name.focus()
		  break;
	  case 1:
		  this.$refs.address1.focus()
		  break;
	  case 2:
		  this.$refs.interests.focus()
		  break;
  }
}

froamer avatar Nov 16 '18 12:11 froamer

I'm having the same issue. Even with @froamer's code, I am unable to get it to work. The event is firing, but it seems to be before the tab has actually changed, so I'm wondering if that could be causing the problem where the form input isn't getting focus? I am able to set the focus within the mounted() call.

Thanks

lundie avatar Jul 15 '19 13:07 lundie

It would be nice if there was a onEnter event for the steps to handle this requirement.

boruchsiper avatar Oct 30 '19 22:10 boruchsiper

I did this...

<form-wizard @on-change="tabChanged">
...
tabChanged(oldIndex, newIndex) {
  switch (newIndex) {
	  case 0:
		  this.$refs.name.focus()
		  break;
	  case 1:
		  this.$refs.address1.focus()
		  break;
	  case 2:
		  this.$refs.interests.focus()
		  break;
  }
}

The workaround is to put the focus code into a setTimeout function with delay of 400. But this is not ideal.

boruchsiper avatar Oct 30 '19 22:10 boruchsiper