Form Field

Display a form field to handle errors and hints.

This is your email address.

Installation

npx nx g @spartan-ng/cli:ui formfield

Usage

import { HlmFormFieldModule } from '@spartan-ng/helm/form-field';
import { HlmInputDirective } from '@spartan-ng/helm/input';
<hlm-form-field>
	<input class="w-80" hlmInput type="email" placeholder="Email" />
	<hlm-hint>This is your email address.</hlm-hint>
</hlm-form-field>

Helm API

SingleFormFieldMock

Selector: single-form-field-example

SingleFormFieldDirtyMock

Selector: single-form-field-dirty-example

HlmError

Selector: hlm-error

Inputs

PropTypeDefaultDescription
class ClassValue --

HlmFormField

Selector: hlm-form-field

Inputs

PropTypeDefaultDescription
class ClassValue --

HlmHint

Selector: hlm-hint

Inputs

PropTypeDefaultDescription
class ClassValue --

Examples

Error

Your name is required

With Form

Changing when error messages are shown

By default, these error messages are shown when the control is invalid and the user has interacted with (touched) the element or the parent form has been submitted. If you wish to override this behavior (e.g. to show the error as soon as the invalid control is dirty or when a parent form group is invalid), you can use the ErrorStateMatcher provider.

For convenience, ShowOnDirtyErrorStateMatcher is available in order to globally cause input errors to show when the input is dirty and invalid

providers: [
    { provide: ErrorStateMatcher, useClass: ShowOnDirtyErrorStateMatcher }
  ]
Label Icon