Skip to content

Commit

Permalink
fix(mask): ensure single % appended on blur and removed on focus
Browse files Browse the repository at this point in the history
  • Loading branch information
georgianastasov committed Jul 1, 2024
1 parent 6f72683 commit 0827e7f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<igx-input-group>
<label igxLabel for="email">Increase</label>
<input igxInput
type="text"
[(ngModel)]="value"
[igxMask]="'000'"
[igxTextSelection]="true"
[focusedValuePipe]="inputFormat"
[displayValuePipe]="displayFormat"/>
<label igxLabel>Increase</label>
<input
igxInput
type="text"
[(ngModel)]="value"
[igxMask]="'000'"
[igxTextSelection]="true"
[focusedValuePipe]="inputFormat"
[displayValuePipe]="displayFormat"
/>
</igx-input-group>
12 changes: 10 additions & 2 deletions src/app/data-display/mask/mask-sample-4/mask-sample-4.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Component, Pipe, PipeTransform } from '@angular/core';
selector: 'app-mask-sample-4',
templateUrl: './mask-sample-4.component.html'
})

export class MaskSample4Component {
public value = 100;
public displayFormat = new DisplayFormatPipe();
Expand All @@ -14,13 +13,22 @@ export class MaskSample4Component {
@Pipe({ name: 'displayFormat' })
export class DisplayFormatPipe implements PipeTransform {
public transform(value: any): string {
return value + ' %';
if (value !== null && value !== undefined) {
value = value.toString().trim();
if (!value.endsWith('%')) {
value += ' %';
}
}
return value;
}
}

@Pipe({ name: 'inputFormat' })
export class InputFormatPipe implements PipeTransform {
public transform(value: any): string {
if (value !== null && value !== undefined) {
value = value.toString().replace(/%/g, '').trim();
}
return value;
}
}

0 comments on commit 0827e7f

Please sign in to comment.