Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
abhayastudios committed Feb 5, 2017
1 parent 6461564 commit 5f20d2b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# NativeScript Phone Validator
# NativeScript Phone Validation

This is a demo project for a phone number validation flow for NativeScript with ng2 (tested on 2.4). It assumes that the backend will use the international phonenumber (E164 format) as the username, but it can be completely customized.

Expand Down
13 changes: 8 additions & 5 deletions app/components/country-code-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {PhoneNumberProvider} from '../providers/phonenumber';
<Label text="Select Country" col="1" class="center header-text"></Label>
<Button text="&#xf00d;" col="2" class="fa header-text close-button" (tap)="params.closeCallback(null)"></Button>
</GridLayout>
<SearchBar #searchBar hint="Search" (propertyChange)="searchCountryCode($event)" (loaded)="preventFocus()"></SearchBar>
<SearchBar #searchBar hint="Search" (propertyChange)="searchCountryCode($event)"></SearchBar>
<ListView [items]="countriesFound" style="margin:10;" rowHeight="75">
<template let-item="item">
<!-- template wrapped in StackLayout for class list-item to take effect -->
Expand Down Expand Up @@ -44,6 +44,7 @@ export class CountryCodeModal implements OnInit {
constructor(private params: ModalDialogParams, public phonenumber: PhoneNumberProvider) {}

ngOnInit() {
this.preventFocus();
this.countriesFound = this.phonenumber.countries;
}

Expand All @@ -63,9 +64,11 @@ export class CountryCodeModal implements OnInit {
*/
private preventFocus() {
if (isAndroid) {
setTimeout(() => {
this.searchBar.nativeElement.android.clearFocus(); // clears focus and dismisses soft keyboard
},10);
if (this.searchBar.nativeElement.android) {
setTimeout(() => { this.searchBar.nativeElement.android.clearFocus(); },0); // clears focus and dismisses soft keyboard
} else {
setTimeout(() => { this.preventFocus(); },10); // sometimes nativeElement is not available yet
}
}
}
}
}
2 changes: 1 addition & 1 deletion app/pages/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class LoginPage implements OnInit {

this.modal.showModal(CountryCodeModal,modalOptions).then((result) => {
//console.dump(result);
if (result!==null && result.hasOwnProperty('iso2') && result.hasOwnProperty('dialCode')) {
if (result && result.hasOwnProperty('iso2') && result.hasOwnProperty('dialCode')) {
this.countryCode = result['iso2'];
this.countryDialCode = '+' + result['dialCode'];
this.setFlagImage();
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nativescript-phone-validation",
"version": "0.0.1",
"version": "0.0.2",
"description": "Phone number validation flow demo project for NativeScript with ng2",
"license": "MIT",
"readme": "NativeScript Application",
Expand All @@ -21,7 +21,7 @@
"version": "2.4.0"
},
"tns-android": {
"version": "2.4.1"
"version": "2.5.0"
}
},
"dependencies": {
Expand Down Expand Up @@ -52,4 +52,4 @@
"typescript": "~2.0.10",
"zone.js": "~0.7.2"
}
}
}

0 comments on commit 5f20d2b

Please sign in to comment.