Skip to content

Commit

Permalink
Hide the soft keyboard when tapping outside of textfields
Browse files Browse the repository at this point in the history
Fixes #6
  • Loading branch information
tjvantoll committed Sep 21, 2015
1 parent a00155b commit c51b41a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
10 changes: 10 additions & 0 deletions app/views/login/login.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var dialogsModule = require("ui/dialogs");
var frameModule = require("ui/frame");
var gesturesModule = require("ui/gestures");
var viewModule = require("ui/core/view");
var UserViewModel = require("../../shared/view-models/user-view-model");

var user = new UserViewModel({
Expand All @@ -19,6 +21,14 @@ exports.loaded = function(args) {
navigationBar.tintColor = UIColor.whiteColor();
}

// Dismiss the keyboard when the user taps outside of the two textfields
var email = viewModule.getViewById(page, "email_address");
var password = viewModule.getViewById(page, "password");
page.observe(gesturesModule.GestureTypes.tap, function() {
email.dismissSoftInput();
password.dismissSoftInput();
});

page.bindingContext = user;
};

Expand Down
2 changes: 1 addition & 1 deletion app/views/login/login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Image src="res://logo" stretch="none" horizontalAlignment="center" />

<TextField id="email_address" text="{{ email }}" hint="Email Address" keyboardType="email" autocorrect="false" autocapitalizationType="none" />
<TextField secure="true" text="{{ password }}" hint="Password" />
<TextField id="password" secure="true" text="{{ password }}" hint="Password" />

<Button text="Sign in" tap="signIn" />
<Button text="Sign up for Groceries" tap="register" cssClass="link" />
Expand Down
8 changes: 8 additions & 0 deletions app/views/password/password.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
var dialogsModule = require("ui/dialogs");
var gesturesModule = require("ui/gestures");
var viewModule = require("ui/core/view");

var UserViewModel = require("../../shared/view-models/user-view-model");
var user = new UserViewModel();

exports.loaded = function(args) {
var page = args.object;
page.bindingContext = user;

// Dismiss the keyboard when the user taps outside textfield
var email = viewModule.getViewById(page, "email");
page.observe(gesturesModule.GestureTypes.tap, function() {
email.dismissSoftInput();
});
};

exports.reset = function() {
Expand Down
10 changes: 10 additions & 0 deletions app/views/register/register.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
var dialogsModule = require("ui/dialogs");
var frameModule = require("ui/frame");
var gesturesModule = require("ui/gestures");
var viewModule = require("ui/core/view");

var UserViewModel = require("../../shared/view-models/user-view-model");
var user = new UserViewModel();

exports.loaded = function(args) {
var page = args.object;
page.bindingContext = user;

// Dismiss the keyboard when the user taps outside of the two textfields
var email = viewModule.getViewById(page, "email");
var password = viewModule.getViewById(page, "password");
page.observe(gesturesModule.GestureTypes.tap, function() {
email.dismissSoftInput();
password.dismissSoftInput();
});
};

function completeRegistration() {
Expand Down
2 changes: 1 addition & 1 deletion app/views/register/register.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Image src="res://logo" stretch="none" horizontalAlignment="center" />

<TextField text="{{ email }}" id="email" hint="Email Address" keyboardType="email" autocorrect="false" autocapitalizationType="none" />
<TextField text="{{ password }}" secure="true" hint="Password" />
<TextField text="{{ password }}" id="password" secure="true" hint="Password" />

<Button text="Sign Up" tap="register" />
</StackLayout>
Expand Down

0 comments on commit c51b41a

Please sign in to comment.