From 51028178ed5b677e7a0c6f8c17a5cb87e94a209a Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Wed, 3 Dec 2014 03:03:16 -0300 Subject: [PATCH] Autofocus and show the second PIN input automatically. Hide submit button. Allow only numbers --- js/controllers/home.js | 39 ++++++++++++++++++++++ js/directives.js | 12 ++++++- views/home.html | 73 ++++++++++++++++++++++++++---------------- 3 files changed, 96 insertions(+), 28 deletions(-) diff --git a/js/controllers/home.js b/js/controllers/home.js index 153ee30f1..6a4d3a2f1 100644 --- a/js/controllers/home.js +++ b/js/controllers/home.js @@ -43,6 +43,45 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc configurable: true }); + Object.defineProperty($scope, + "newpin", { + get: function() { + return this._newpin; + }, + set: function(newValue) { + this._newpin = newValue; + if (newValue && newValue.length == 4) { + // next input + $scope.$$childTail.secondPin = true; + } + }, + enumerable: true, + configurable: true + }); + + Object.defineProperty($scope, + "repeatpin", { + get: function() { + return this._repeatpin; + }, + set: function(newValue) { + this._repeatpin = newValue; + if (newValue && newValue.length == 4) { + if ($scope.$$childTail._newpin === newValue) { + // save and submit + $scope.createPin($scope.$$childTail.setPinForm); + } + else { + $scope.error = 'Pin must match!'; + } + } + if (!newValue) { + $scope.error = null; + } + }, + enumerable: true, + configurable: true + }); $scope.done = function() { $rootScope.starting = false; diff --git a/js/directives.js b/js/directives.js index ac823cdb1..993357694 100644 --- a/js/directives.js +++ b/js/directives.js @@ -286,10 +286,20 @@ angular.module('copayApp.directives') link: function(_scope, _element) { $timeout(function() { _element[0].focus(); - }, 0); + }); } }; }) + .directive('showFocus', function($timeout) { + return function(scope, element, attrs) { + scope.$watch(attrs.showFocus, + function (newValue) { + $timeout(function() { + newValue && element[0].focus(); + }); + },true); + }; + }) .directive('match', function() { return { require: 'ngModel', diff --git a/views/home.html b/views/home.html index 5c7fcff60..5d75090da 100644 --- a/views/home.html +++ b/views/home.html @@ -47,62 +47,81 @@ creating your profile -
+

Set your PIN number

+
+
+ +
+ + {{error|translate}} + +
+
-
- + + ng-pattern="/^[0-9]{1,4}$/" + placeholder="Pin number" name="newpin" required show-focus="!secondPin">
-
+
+ ng-pattern="/^[0-9]{1,4}$/" + placeholder="Repeat pin number" name="repeatpin" required show-focus="secondPin">
-

- - {{'Pin must match'|translate}} -

- - -

Enter your PIN number

-

- - {{error|translate}} -

+
+
+ +
+ + {{error|translate}} + +
+
-
-