Skip to content

Commit 84bd12f

Browse files
committed
Phone number style changes
1 parent 578249e commit 84bd12f

File tree

7 files changed

+61
-27
lines changed

7 files changed

+61
-27
lines changed

src/app/modules/examples/components/contact-form/contact-form.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="contact-form">
2-
<div class="mobile-number">
2+
<div class="contact-mobile-number">
33
<app-mobile-number [group]="contactForm"
44
[contryCode]="contactForm.controls['contryCode']"
55
[mobileNumber]="contactForm.controls['mobileNumber']"></app-mobile-number>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.contact-form {
2+
padding: 20px;
3+
}

src/app/shared/ui-components/input/input.component.html

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
</mat-form-field> -->
66
<div class="form-control" [formGroup]="formGroup"
77
[ngClass]="extraClass" [class.invalid]="control.touched && control.invalid">
8-
<!-- <mat-form-field [formControl]="control"> -->
8+
<mat-form-field>
9+
<mat-label *ngIf="label">{{label}}</mat-label>
910
<input matInput
1011
[type]="type"
1112
[placeholder]="placeholder"
@@ -20,16 +21,16 @@
2021
[appNoSpace]="noSpace"
2122
autocomplete="off"
2223
(blur)="blur()" />
23-
<p *ngIf="errorMessage" class="error-message">{{errorMessage}}</p>
24-
<p *ngIf="control.touched && control.invalid" class="error-message">
24+
<mat-error *ngIf="errorMessage">{{errorMessage}}</mat-error>
25+
<mat-error *ngIf="control.touched && control.invalid">
2526
{{
2627
(control.errors.required) ? "Please enter "+name.toLowerCase() :
2728
(control.errors.minlength) ? name + " must be greater than " + (control.errors.minlength.requiredLength-1) :
2829
(control.errors.maxlength) ? name + " must be lesser than " + control.errors.maxlength.requiredLength :
2930
'Please enter a valid '+name
3031
}}
31-
</p>
32-
<!-- </mat-form-field> -->
32+
</mat-error>
33+
</mat-form-field>
3334
</div>
3435
</ng-container>
3536

src/app/shared/ui-components/input/input.component.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
1+
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
22
import { FormControl, FormGroup } from '@angular/forms';
33
import { AppConstants } from 'src/app/utilities/constants/AppConstants';
44

@@ -9,6 +9,12 @@ import { AppConstants } from 'src/app/utilities/constants/AppConstants';
99
})
1010
export class InputComponent implements OnInit {
1111

12+
constructor(
13+
private ref: ChangeDetectorRef
14+
) {
15+
this.onBlur = new EventEmitter();
16+
}
17+
1218
@Input() appAutoFocus = false;
1319
@Input() formGroup: FormGroup;
1420
@Input() control: FormControl;
@@ -37,8 +43,10 @@ export class InputComponent implements OnInit {
3743
// tslint:disable-next-line: no-output-on-prefix
3844
@Output() onBlur: EventEmitter<boolean>;
3945

40-
constructor() {
41-
this.onBlur = new EventEmitter();
46+
ngOnChanges(change) {
47+
if (change.errorMessage) {
48+
this.ref.detectChanges();
49+
}
4250
}
4351

4452
ngOnInit() { }
Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
1-
<mat-form-field [formGroup]="group">
2-
<mat-select placeholder="" #singleSelect name="countryCodeNum" [formControl]="contryCode">
3-
<mat-option>
4-
<ngx-mat-select-search [formControl]="countryCodeSearchVal"
5-
placeholderLabel="Search phone code"
6-
noEntriesFoundLabel="'No matching codes found'"></ngx-mat-select-search>
7-
</mat-option>
8-
<mat-option [value]="code['phone_code']" *ngFor="let code of filterCountryCode"
9-
(click)="isPhoneValid(code['name'])">
10-
{{'+ ' + code['phone_code']}}
11-
<span class="phone-code-float">({{code['name']}})</span>
12-
</mat-option>
13-
</mat-select>
14-
</mat-form-field>
15-
<app-input [placeholder]="'Mobile number'" [name]="'Mobile number'" [id]="'contact_mobile_number'"
16-
[formGroup]="group" [control]="mobileNumber" [onlyNumber]="true"
17-
[errorMessage]="errorMessage" (onBlur)="isPhoneValid()"></app-input>
1+
<div class="mobile-number">
2+
<div class="mobile-code">
3+
<mat-form-field [formGroup]="group" class="mobile-code-form">
4+
<mat-select placeholder="" #singleSelect name="countryCodeNum" [formControl]="contryCode">
5+
<mat-option>
6+
<ngx-mat-select-search [formControl]="countryCodeSearchVal"
7+
placeholderLabel="Search phone code"
8+
noEntriesFoundLabel="'No matching codes found'"></ngx-mat-select-search>
9+
</mat-option>
10+
<mat-option [value]="code['phone_code']" *ngFor="let code of filterCountryCode"
11+
(click)="isPhoneValid(code['name'])">
12+
{{'+ ' + code['phone_code']}}
13+
<span class="phone-code-float">({{code['name']}})</span>
14+
</mat-option>
15+
</mat-select>
16+
<mat-error *ngIf="contryCode.touched && contryCode.invalid">
17+
{{
18+
(contryCode.errors.required) ? "Please enter country code" : 'Please enter a valid country code'
19+
}}
20+
</mat-error>
21+
</mat-form-field>
22+
</div>
23+
<div class="mobile-input">
24+
<app-input [placeholder]="'Mobile number'" [name]="'Mobile number'" [id]="'contact_mobile_number'"
25+
[formGroup]="group" [control]="mobileNumber" [onlyNumber]="true"
26+
[errorMessage]="errorMessage" (onBlur)="isPhoneValid()"></app-input>
27+
</div>
28+
</div>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.mobile-number {
2+
display: inline-flex;
3+
.mobile-code-form {
4+
max-width: 100px;
5+
}
6+
.mobile-input {
7+
margin-left: 10px;
8+
}
9+
}

src/app/shared/ui-components/mobile-number/mobile-number.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ export class MobileNumberComponent implements OnInit {
5959
if (codeName) {
6060
this.selectedCodeName = codeName;
6161
}
62-
if (this.mobileNumber.valid && this.mobileNumber.value) {
62+
if (this.mobileNumber.valid && this.mobileNumber.value && this.selectedCodeName) {
6363
const phoneCheck = phoneUtil.parseAndKeepRawInput(this.mobileNumber.value, this.selectedCodeName);
6464
if (!phoneUtil.isValidNumber(phoneCheck)) {
6565
this.errorMessage = 'Please enter a valid phone number';
66+
} else {
67+
this.errorMessage = null;
6668
}
6769
} else {
6870
this.errorMessage = null;

0 commit comments

Comments
 (0)