I have the following code, which results in a single password input being rendered with the toggler overlaying the visible input. The ion-toggle directive toggles visibility of the two inputs.
<label class="item item-input">
<input placeholder="Password" ng-hide="showPassword" type="password">
<input placeholder="Password" ng-if="showPassword" type="text">
<ion-toggle ng-model="showPassword" toggle-class="toggle-energized"> </ion-toggle>
</label>
When the toggler has focus, the software keyboard retracts. The user has to then tap back into the input to show the keyboard again.
How can I programmatically show/retain the keyboard when the toggler has focus? I've tried writing a directive to force focus back onto the inputs, but that feels clunky, and there's the issue of there being two inputs.
Here's a basic demo. You won't get a keyboard in a desktop browser, of course.
Thank you.
I created a directive which will give focus on
passwordfield whentooglebutton is clicked. Also refactored html of password field instead of two field it will only show one field.Markup
Directive
Forked Codepen
Edit
Directive has implemented in such a way that we are passing to toggling flag name to the
showPasswordinside directive attribute likedo-focus="showPassword"so that directive will put$watchon the scope variable by usingattrs.doFocus, watcher function gets fired and when you toggle theshowPasswordbutton. Basically this inner watcher isscope.$watch('showPassword'. Then the function first parameter would benewValuewhich is changed value &oldValuemeans the previous value ofshowPasswordmodel. Here in your casenewValue&oldValueare just redundant they are just not use anywhere, but if you wanted to do something on there change then they could help you.