Skip to main content
cngx-src documentation

CngxInputFormat

DirectivePrimaryv0.1.0WCAG AA

projects/forms/input/input-format.directive.ts

Import#

import { CngxInputFormat } from '@cngx/forms/input'

Description#

Display formatting on blur, raw value on focus.

Applies a format function when the input loses focus and a parse function when it gains focus. The directive's value model carries the raw (unformatted) value; bind it via [(value)] or wrap the input in <cngx-form-field [field]="f.x"> for Signal Forms.

<!-- Currency formatting -->
<input [cngxInputFormat]="formatCurrency" [parse]="parseCurrency" [(value)]="amount" />

<!-- Phone formatting inside a Signal-Forms field -->
<cngx-form-field [field]="f.phone">
  <input cngxInputFormat="formatPhone" cngxBindField [control]="f.phone" />
</cngx-form-field>

https://cngxjs.github.io/cngx/examples/#/forms/input/utilities/input-format

Metadata#

Host#

Providers#

Relationships

Index#

Properties

Outputs

Derived State

HostListeners

Inputs#

format#FormatFn
input()Required

Format function applied on blur.

default { alias: 'cngxInputFormat' }
input()

Parse function applied on focus (inverse of format). Default: identity.

default (v: string) => v
value#string
model()

Primary value channel — raw (unformatted) string.

default '', { alias: 'value' }

Outputs#

value#string
model()

Primary value channel — raw (unformatted) string.

Instance Properties#

rawValue#Signal
Readonly
Read `value` directly. Kept one release for migration.
this.value

HostListeners#

EventHandler
(focus)focus()
(blur)blur()
(input)input()