<kbq-form-field> is a component used to create forms and input fields with support for styling and additional features.

Used to sign in and to receive notifications

The following components are intended to work inside the <kbq-form-field> component:

<kbq-label> names the field. The showRequiredMarker attribute ends the label of a required field with the * marker: a field is required when it has the required attribute or the Validators.required validator. The marker is hidden by default; the global options turn it on for every field.

To create a horizontal form, add the horizontal attribute to the <kbq-form-field> component.

Hint below the field
Hint below the field
Hint below the field
Hint below the field

<kbq-hint> is a component used to add hints to form fields inside the <kbq-form-field> component. Hints can be useful for providing additional information on how to fill out the field, what data is expected, or for displaying additional instructions.

Max 25 chars (0/25)

<kbq-error> is a component used to display validation error messages for form fields inside the <kbq-form-field> component. Errors are initially hidden and will be displayed only for invalid form fields after user interaction or form submission.

Enter email

By default, error highlighting and messages are displayed for invalid fields after user interaction (touched or form submitted) with the form element. This behavior can be overridden using ErrorStateMatcher, which provides the ability to flexibly configure the logic for highlighting and displaying validation errors, allowing you to adapt the behavior of input fields to the specific requirements of the application.

You can use one of the built-in ErrorStateMatcher, or write your own implementation:

/**
 * Highlights and displays an error for an invalid field after form submission
 * Copy of ShowOnFormSubmitErrorStateMatcher: https://github.com/koobiq/angular-components/blob/main/packages/components/core/error/error-state-matcher.ts
 */
class CustomErrorStateMatcher implements ErrorStateMatcher {
    isErrorState(control: AbstractControl | null, form: FormGroupDirective | NgForm | null): boolean {
        return !!(control?.invalid && form?.submitted);
    }
}

Override

For a specific field, using the errorStateMatcher attribute:

Error will be shown when the control is invalid and the form is submitted

For all fields, using the ErrorStateMatcher token:

Error will be shown when the control is invalid and the form is submitted

For a full explanation of both approaches, built-in matchers, and component-specific patterns (tag list, file upload), see the Validation guide.

<kbq-cleaner /> is a component that adds a clear button for filled form fields inside the <kbq-form-field> component.

kbqPrefix and kbqSuffix are directives that allow adding custom elements before and after the form field inside the <kbq-form-field> component. These directives are useful for adding icons, text, buttons, and other elements that should be placed next to the form field.

In text input fields, a blue border is always displayed when focused, regardless of the activation method (mouse, keyboard, or touch). For form elements with dropdown lists (such as: select, timezone, and tree select), the focus border is shown only during keyboard navigation (using the Tab key) and is hidden when the dropdown list is opened.

For a specific field, using the noBorders attribute:

For all fields, in the global options.

To change the tint or switch it off, override the token on the field:

.my-form-field {
    /* look exactly like a normally filled field */
    --kbq-form-field-states-autofill-background: transparent;
}

The state is also tracked in TypeScript. KbqInput, KbqInputPassword, KbqTextarea and KbqTagInput (forwarded by KbqTagList) each wrap the CDK's AutofillMonitor around their own element and expose the result as an autofilled signal, which <kbq-form-field> reflects as the kbq-form-field_autofilled class:

readonly input = viewChild.required(KbqInput);

// ...

const filledByBrowser = this.input().autofilled();

The signal is a hook for application code, not the mechanism behind the styling: it arrives a frame or two after the browser paints, where the CSS matches in the same style pass.

<kbq-password-toggle> is a component that adds a "Show password" button for filled <input kbqInputPassword /> fields inside the <kbq-form-field> component.

<kbq-reactive-password-hint> is a component used to add hints to the <input kbqInputPassword /> field inside the <kbq-form-field> component. The [hasError] input sets the state of the hint: bind it to the error of the matching validator of the form control.

The example uses PasswordValidators - a set of static methods for password validation.

Min length (0/8) Uppercase characters (0/2) Lowercase characters (0/2) Number characters (0/2) Special characters (0/2)

This error occurs when <kbq-form-field> does not contain a form field, such as <input kbqInput /> or its import KbqInputModule.

This error occurs when <kbq-password-toggle> cannot find the <input kbqInputPassword /> field or its import KbqInputModule.

This error occurs when <kbq-stepper> cannot find the <input kbqNumberInput /> field or its import KbqInputModule.

The kbqFormFieldDefaultOptionsProvider function sets the default options of every field in the application or in a specific injector.

import { ApplicationConfig } from '@angular/core';
import { kbqFormFieldDefaultOptionsProvider } from '@koobiq/components/form-field';

export const appConfig: ApplicationConfig = {
    providers: [kbqFormFieldDefaultOptionsProvider({ showRequiredMarker: true, noBorders: true })]
};
Suggestions for improvement
If you found a mistake or want to improve the article, create an issue on GitHub.