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
password
field whentoogle
button 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
showPassword
inside directive attribute likedo-focus="showPassword"
so that directive will put$watch
on the scope variable by usingattrs.doFocus
, watcher function gets fired and when you toggle theshowPassword
button. Basically this inner watcher isscope.$watch('showPassword'
. Then the function first parameter would benewValue
which is changed value &oldValue
means the previous value ofshowPassword
model. Here in your casenewValue
&oldValue
are just redundant they are just not use anywhere, but if you wanted to do something on there change then they could help you.