Developer Programs

Learn

Docs

Angular Directives for Formatting Input

Technical Info > Framework Considerations: Angular > Angular Directives for Formatting Input

Begin by importing the JhaResponsiveCoreModule into your application.

Import the JhaResponsiveCoreModule module
// import into app.module
import { JhaResponsiveCoreModule } from '@jkhy/responsive-ui-angular/jha-responsive-core';

@NgModule({
    imports: [
        ...
        JhaResponsiveCoreModule.forRoot(),
        ...
    ]
})

export class AppModule(){}

jhaCurrencyInput

Add the jhaCurrencyInput directive to inputs that prompt for currency. This directive formats the input’s value as currency after the user exits the field. Non-currency characters are removed from the value and the decimal portion is padded to 2 places.

Using the jhaCurrencyInput directive
<input id="GrossIncome" name="GrossIncome" type="number" step="0.01" jhaCurrencyInput
    class="form-control" [(ngModel)]="customerInfo.grossIncome" autocomplete="off"
    autocorrect="off" autocapitalize="off" spellcheck="false" />

jhaDecimalInput

Add the jhaDecimalInput attribute directive to inputs that prompt for numeric values, where you need a specific number of decimal places shown after the decimal point; use the jhaDecimalPlaces attribute to specify the number of decimal places. The value is formatted after the user exits the field.

Using the jhaDecimalInput directive
<input id="InterestRate" name="InterestRate" type="number"
    jhaDecimalInput jhaDecimalPlaces="3" class="form-control"
    [(ngModel)]="customerInfo.interestRate" autocomplete="off"
    autocorrect="off" autocapitalize="off" spellcheck="false" />

jhaZeroPaddedNumber

Add the jhaZeroPaddedNumber attribute directive to inputs that prompt for numeric values, where the value must be padded with zeros to a specified length; use the jhaLength attribute to specify the total number of digits that must be present. The value is formatted after the user exits the field.

Using the jhaZeroPaddedNumber directive
<input id="SSN" name="SSN" type="number" jhaZeroPaddedNumber jhaLength="9" class="form-control"
    [(ngModel)]="customerInfo.ssn" required autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />

Support options
Have questions on this topic?
Join the Responsive UI team in Microsoft Teams to connect with the community.
See something in this page that needs to change?
Send us feedback on this page.
Last updated Tue Jun 6 2023