javascript - Losing autofus on Vue.js toggle of v-show -


strange, autofocus attribute of inputs don't work when changing element being displayed

see fiddle attached: https://jsfiddle.net/e53lgnnb/6/

code: html:

<body> <!-- email [post] --> <div class="" id="email" v-show="activestep == 'email'">     <form action="onboarding-5.html" @submit.prevent="submitform('email', 'password')">         <div class="form-row">             <input type="email" autofocus required placeholder="email">         </div>         <p>             <button type="submit" class="button">ok <i class="icon arrow-right"></i></button>         </p>     </form> </div>  <!-- password [post] --> <div class="onboarding-content-wrap" id="password" v-show="activestep == 'password'">     <form action="onboarding-6.html">         <div class="form-row">             <input type="password" autofocus required placeholder="password">         </div>         <p>             <button type="submit" class="button">ok <i class="icon arrow-right"></i></button>         </p>     </form> </div> </body> 

js:

    new vue({     el: 'body',      data: {         activestep: 'email',     },      methods: {          // show step active         getnextstep: function (nextstep) {             this.activestep = nextstep;         },          submitform: function (currentstep, nextstep) {             this.getnextstep(nextstep);             console.log(response.data);         }     } }); 

what's going on? lot !

autofocus works on page load. if want change focus when user submit form, suggest create watch "activestep".

something this

watch:{     activestep(step){         if( step === 'email'){             this.$els.emailfield.focus();         }         // ...     } }, 

more info:

the autofocus content attribute allows author indicate control focused page loaded, allowing user start typing without having manually focus main control.

there must not 2 elements same nearest ancestor autofocus scoping root element both have autofocus attribute specified.

https://www.w3.org/tr/html5/forms.html#attr-fe-autofocus


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -