Skip to content

Commit 2a573eb

Browse files
Merge pull request #3504 from IgniteUI/ganastasov/fix-3493-vnext
fix(mask): ensure single % appended on blur and removed on focus
2 parents 6f72683 + 0827e7f commit 2a573eb

2 files changed

Lines changed: 20 additions & 10 deletions

File tree

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<igx-input-group>
2-
<label igxLabel for="email">Increase</label>
3-
<input igxInput
4-
type="text"
5-
[(ngModel)]="value"
6-
[igxMask]="'000'"
7-
[igxTextSelection]="true"
8-
[focusedValuePipe]="inputFormat"
9-
[displayValuePipe]="displayFormat"/>
2+
<label igxLabel>Increase</label>
3+
<input
4+
igxInput
5+
type="text"
6+
[(ngModel)]="value"
7+
[igxMask]="'000'"
8+
[igxTextSelection]="true"
9+
[focusedValuePipe]="inputFormat"
10+
[displayValuePipe]="displayFormat"
11+
/>
1012
</igx-input-group>

src/app/data-display/mask/mask-sample-4/mask-sample-4.component.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Component, Pipe, PipeTransform } from '@angular/core';
44
selector: 'app-mask-sample-4',
55
templateUrl: './mask-sample-4.component.html'
66
})
7-
87
export class MaskSample4Component {
98
public value = 100;
109
public displayFormat = new DisplayFormatPipe();
@@ -14,13 +13,22 @@ export class MaskSample4Component {
1413
@Pipe({ name: 'displayFormat' })
1514
export class DisplayFormatPipe implements PipeTransform {
1615
public transform(value: any): string {
17-
return value + ' %';
16+
if (value !== null && value !== undefined) {
17+
value = value.toString().trim();
18+
if (!value.endsWith('%')) {
19+
value += ' %';
20+
}
21+
}
22+
return value;
1823
}
1924
}
2025

2126
@Pipe({ name: 'inputFormat' })
2227
export class InputFormatPipe implements PipeTransform {
2328
public transform(value: any): string {
29+
if (value !== null && value !== undefined) {
30+
value = value.toString().replace(/%/g, '').trim();
31+
}
2432
return value;
2533
}
2634
}

0 commit comments

Comments
 (0)