Tôi đang làm việc trên Ứng dụng Ionic với AngularJS.Nhập tập trung lỏng ngay lập tức trên Android sau khi tập trung với javascript
Tôi có vài đầu vào (công cụ đăng nhập/đăng ký) và khi phím Enter được nhấn nút -go trên Android và tương đương trên iOS- là KeyCode 13
, nó tập trung vào đầu vào tiếp theo với trợ giúp chỉ thị tùy chỉnh.
Nó hoạt động hoàn hảo trên trình duyệt web, nhưng trên điện thoại, nó tập trung đầu vào tiếp theo, sau đó tiêu điểm bị mất ngay lập tức và bàn phím tự ẩn, buộc người dùng nhấp lại vào đầu vào.
Đây là HTML:
<ion-view title="First Screen" hide-nav-bar="true" id="firstScreen" class=" ">
<ion-content padding="false" style="background: url(img/XAYpMMdUTvWFVAnrEhUi_restaurant.jpg) no-repeat center;background-size:cover;" class=" manual-remove-top-padding" scroll="false">
<div class="">
<img src="img/awdYDbeeSlSHCToXN5Lw_logo.png" width="auto" height="30%" style="display: block; margin-left: auto; margin-right: auto;">
</div>
<label class="item item-input " id="emailInput" name="email">
<input class="invisible-input" type="email" placeholder="Email" ng-model="user.email" focus-me="currentInput == 0" ng-keyup="inputKeyEvent($event, 0)">
</label>
<label class="item item-input " id="passwordInput" name="password">
<input class="invisible-input" type="password" placeholder="Mot de passe" focus-me="currentInput == 1" ng-model="user.password" ng-keyup="inputKeyEvent($event, 1)">
</label>
<label ng-show="isSignUp" class="item item-input " ng-class="{'animated fadeInLeft': isSignUp, 'animated fadeOutLeft' : !isSignUp && changed }" id="confirmPasswordInput" name="password">
<input class="invisible-input" type="password" placeholder="Confirmation du mot de passe" focus-me="currentInput == 2" ng-model="user.confirmation" ng-keyup="inputKeyEvent($event, 2)">
</label>
<div>
{{response}}
</div>
<div class="actionButtonContainer">
<button ng-click="signin()" id="loginButton" class=" button button-balanced button-full">Se oonnecter</button>
<button ng-click="signup()" id="signupButton" class=" button button-energized button-full" ng-disabled="disableSignUp()">S'inscrire</button>
</div>
</ion-content>
Đây là chỉ:
directive('focusMe', function() {
return {
link: function (scope, element, attrs) {
scope.$watch(attrs.focusMe, function (value) {
if (value === true) {
element[0].focus();
}
});
}
};
Và đây là phương pháp điều khiển đó là tham gia:
$scope.inputKeyEvent = function(event, inputId)
{
$scope.response = event.keyCode;
if (event.keyCode == 13)
{
$scope.currentInput = inputId + 1;
if ($scope.currentInput == 2 && !$scope.isSignUp)
$scope.signin();
else if ($scope.currentInput == 3 && $scope.isSignUp)
$scope.signup();
}
}
Cảm ơn sự giúp đỡ của bạn!
EDIT
Vấn đề là giả lập genymotion của tôi, nó hoạt động hoàn hảo trên điện thoại thật (ít nhất là tôi.)
Xin lỗi vì bình luận lạc đề, nhưng đối với tương lai tham khảo, động từ là "mất": http://grammarist.com/usage/loose-lose/ –
@LukeH cảm ơn: D – Sorikairo