Skip to content

Mask Directive Specification

Stefana Andreeva edited this page Feb 28, 2018 · 7 revisions

igxMask Directive Specification

Objectives

IgxMask directive should provide means for controlling user input and formatting the visible value based on a configurable mask rules.

Developer

As a developer I want to be able to apply a mask on an input field so that the user can only type a predetermined pattern.

<input type="text" igxInput [igxMask]="myMask"/>

The following built-in mask rules should be supported:

  • 0: requires a digit (0-9).
  • 9: requires a digit (0-9).
  • #: requires a digit (0-9), plus (+), or minus (-) sign.
  • L: requires a letter (a-Z).
  • ?: Requires a letter (a-Z).
  • A: requires an alphanumeric (0-9, a-Z).
  • a: requires an alphanumeric (0-9, a-Z).
  • &: any keyboard character.
  • C: any keyboard character.

Static symbols (literals) in the mask pattern should also be supported.

As a developer I want to be able specify the character used for the unfilled parts of the mask (prompt char).

As a developer I want to be able to either include the mask literals in the underlying component value, or preserve its row value.

As a developer I want to be able to implement custom logic when the input value changes while the user interacts with the component.

End user

The 'masked' value is formatted when the user interacts with the component by pasting, deleting or typing in the input field.

End User Experience

User input is masked.

Developer Experience

Use the directive on an input element.

<input type="text" igxInput [value]="1234567890" [igxMask]="'(000) 0000-000'"/>

Include mask literals in the the underlying component value.

public myValue = "1234567890";
public myMask = "(000) 0000-000";

<input type="text" igxInput [(ngModel)]="myValue" [igxMask]="myMask" [includeLiterals]="true"/>

Exclude mask literals from the the underlying component value.

public myValue = "1234567890";
public myMask = "(000) 0000-000";

<input type="text" igxInput [(ngModel)]="myValue" [igxMask]="myMask" [includeLiterals]="false"/>

Implement custom logic when the value changes

myValue = "1234567890";
myMask = "(000) 0000-000";
row: string;
formatted: string;

handleValueChange(event) {
  this.row = event.rowValue;
  this.formatted = event.formattedVal;
}


<input type="text" igxInput [(ngModel)]="myValue" [igxMask]="myMask" (dataValueChange)="handleValueChange($event)"/>

<div>Row value: {{row}}</div>
<div>Formatted value: {{formatted}}</div>

API

Inputs

Name Description
mask Represents the current mask
promptChar Placeholder character representing a fillable spot in the mask (default is underscore)
includeLiterals Indicates whether to include literals in the raw value

Outputs

Name Description
dataValueChange Fires each time the value changes
Clone this wiki locally