Skip to content

Commit

Permalink
v1.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
azzamasghar1 committed Jun 9, 2021
1 parent 2685487 commit e301f1e
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 137 deletions.
56 changes: 35 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ An Ionic component for International Phone Number Input, that allows all countri
+ [Step 3: Add it to template.](#Step-3-Add-it-to-template)
+ [Step 4: Configure it.](#Step-4-Configure-it)
+ [Step 5: Add validation.](#Step-5-Add-validation)
+ [Step 6: Configure validation.](#Step-6-Configure-validation)
* [Options](#Options)
* [Events](#Events)
* [Contributing](#Contributing)
Expand Down Expand Up @@ -49,7 +48,7 @@ Add the following to your `styles` array of project in `angular.json` (located i

### Step 2: Import it.

First, import `IsIonIntlTelInputModule` to your `app.module.ts` that is normally located in `src\app\app.module.ts`.
First, import `IonIntlTelInputModule` to your `app.module.ts` that is normally located in `src\app\app.module.ts`.

```
import { IonIntlTelInputModule } from 'ion-intl-tel-input';
Expand All @@ -63,10 +62,10 @@ export class AppModule { }
```

**Note:** Additionally, if you are using lazy loaded pages. Check if your pages have a module file, for example, `home.module.ts`, and if they do then import `IsIonIntlTelInputModule` to each page module too.
**Note:** Additionally, if you are using lazy loaded pages. Check if your pages have a module file, for example, `home.module.ts`, and if they do then import `IonIntlTelInputModule` to each page module too.

```
import { IonIntlTelInputModule } from 'ionic-selectable';
import { IonIntlTelInputModule } from 'ion-intl-tel-input';
import { HomePage } from './home';
@NgModule({
Expand Down Expand Up @@ -114,22 +113,43 @@ export class HomePageModule { }

#### a. Usage with Template Driven Forms
```
import { IonIntlTelInputModel } from 'ion-intl-tel-input';
phone: IonIntlTelInputModel = {
dialCode: '+92',
internationalNumber: '+92 300 1234567',
isoCode: 'pk',
nationalNumber: '300 1234567'
};
@Component({ ... })
export class HomePage {
phoneNumber = '';
phoneNumber = {
dialCode: '+92',
internationalNumber: '+92 300 1234567',
isoCode: 'pk',
nationalNumber: '300 1234567'
};
constructor() { }
}
```

#### b. Usage with Reactive Forms
```
import { IonIntlTelInputModel } from 'ion-intl-tel-input';
@Component({ ... })
export class HomePage implements OnInit {
formValue = {phoneNumber: '', test: ''};
phone: IonIntlTelInputModel = {
dialCode: '+92',
internationalNumber: '+92 300 1234567',
isoCode: 'pk',
nationalNumber: '300 1234567'
};
formValue = {phoneNumber: this.phone};
form: FormGroup;
constructor() { }
Expand Down Expand Up @@ -198,27 +218,21 @@ export class HomePage implements OnInit {
</form>
```

### Step 6: Configure validation.

#### a. Usage with Template Driven Forms
```
@Component({ ... })
export class HomePage {
phoneNumber = '';
constructor() { }
}
```

#### b. Usage with Reactive Forms
And in your `.ts` file:
```
import { IonIntlTelInputModel } from 'ion-intl-tel-input';
import { IonIntlTelInputValidators } from 'is-ion-intl-tel-input';
@Component({ ... })
export class HomePage implements OnInit {
formValue = {phoneNumber: '', test: ''};
phone: IonIntlTelInputModel = {
dialCode: '+92',
internationalNumber: '+92 300 1234567',
isoCode: 'pk',
nationalNumber: '300 1234567'
};
formValue = {phoneNumber: this.phone};
form: FormGroup;
constructor() { }
Expand Down
Binary file added ion-intl-tel-input-1.0.2.tgz
Binary file not shown.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0.2",
"version": "1.0.5",
"name": "ion-intl-tel-input",
"title": "Ion Intl Tel Input",
"description": "An Ionic component for International Phone Number Input, that allows all countries, validation with google phone lib, limited countries, preferred countries, virtual scrolling and much more.",
Expand Down Expand Up @@ -30,7 +30,8 @@
"phone",
"phonenumber",
"telephone",
"number"
"number",
"elktech"
],
"scripts": {
"ng": "ng",
Expand All @@ -40,7 +41,7 @@
"lint": "ng lint",
"e2e": "ng e2e",
"build_lib": "ng build ion-intl-tel-input",
"serve": "ng build ion-intl-tel-input --watch",
"serve_lib": "ng build ion-intl-tel-input --watch",
"npm_pack": "cd dist/ion-intl-tel-input && npm pack",
"package": "npm run build_lib && npm run npm_pack",
"publish": "npm run package && cd dist/ion-intl-tel-input && npm publish"
Expand Down
5 changes: 3 additions & 2 deletions projects/ion-intl-tel-input/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0.2",
"version": "1.0.5",
"name": "ion-intl-tel-input",
"title": "Ion Intl Tel Input",
"description": "An Ionic component for International Phone Number Input, that allows all countries, validation with google phone lib, limited countries, preferred countries, virtual scrolling and much more.",
Expand Down Expand Up @@ -30,7 +30,8 @@
"phone",
"phonenumber",
"telephone",
"number"
"number",
"elktech"
],
"peerDependencies": {
"ionic-selectable": "^4.5.2",
Expand Down
33 changes: 15 additions & 18 deletions projects/ion-intl-tel-input/src/lib/ion-intl-tel-input.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,33 @@ import { PhoneNumber, PhoneNumberUtil } from 'google-libphonenumber';
export class IonIntlTelInputValidators {
static phone(control: AbstractControl): ValidationErrors | null {
const error = { phone: true };
const isRequired = control.errors && control.errors.required;
let phoneNumber: PhoneNumber;

if (!control.value) {
return error;
}

try {
phoneNumber = PhoneNumberUtil.getInstance().parse(
control.value.number,
control.value.nationalNumber,
control.value.isoCode
);
} catch (e) {
if (!isRequired) {
return error;
}
return error;
}

if (control.value) {
if (!phoneNumber) {
if (!phoneNumber) {
return error;
} else {
if (
!PhoneNumberUtil.getInstance().isValidNumberForRegion(
phoneNumber,
control.value.isoCode
)
) {
return error;
} else {
if (
!PhoneNumberUtil.getInstance().isValidNumberForRegion(
phoneNumber,
control.value.isoCode
)
) {
return error;
}
}
}
return;
}
}

Expand All @@ -92,7 +90,6 @@ export class IonIntlTelInputValidators {
})
export class IonIntlTelInputValidatorDirective implements Validator {
validate(control: AbstractControl): ValidationErrors | null {
console.log('validate');
return IonIntlTelInputValidators.phone(control);
}
}
Loading

0 comments on commit e301f1e

Please sign in to comment.