Forms

Every input is a Signal Forms control: bind it with [formField], put the rules in the form's schema, and a scField round it shows the label, the description and the errors — named, described and marked invalid for screen readers too.

Signal Forms only

The library is built for Angular's Signal Forms (@angular/forms/signals): no ngModel, no reactive forms. A control — an input, a select, a checkbox, a combobox, a date picker, the Number Group, the OTP Input… — takes its value, its state and its errors from the field you bind: [formField]="profileForm.email".

import { signal } from '@angular/core';import { FormField, form } from '@angular/forms/signals';
readonly profile = signal({ name: '', email: '', plan: 'free' });readonly profileForm = form(this.profile);

A field

scField holds one control with its text: the label names it, a description and the errors are read with it (aria-describedby), and once it is touched and invalid, the field and its control say so (data-invalid, aria-invalid) and the errors show.

<div scField>  <label scLabel>Email</label>  <input scInput type="email" [formField]="profileForm.email" />  <p scFieldDescription>We never share it.</p>  <p scFieldErrors></p></div>

The control is anything that takes [formField]: give it the field's scLabel and nothing else. See Field for rows, groups, choice cards and fieldsets.

Rules in the schema

Required, minimum and maximum, lengths, patterns and the disabled state are the schema's, not attributes on the control: the form knows them, checks them and hands them to the control (an input gets its required, a Number Group its bounds). Give each validator a message: it is what the errors show, in your words — and your translations.

import { disabled, email, form, maxLength, required } from '@angular/forms/signals';
readonly profileForm = form(this.profile, (path) => {  required(path.name, { message: 'Enter your name.' });  maxLength(path.name, 80, { message: 'At most 80 characters.' });  required(path.email, { message: 'Enter your email.' });  email(path.email, { message: 'That is not an email.' });  disabled(path.plan, () => !this.canChangePlan());});

The bounds of a slider, a number or a range are these rules too: with a form, the control takes them from the schema (Angular refuses [min] or [max] beside [formField]). A range — a pair of values — gets them on each value:

readonly priceForm = form(this.model, (path) =>  // <div scRangeSlider [formField]="priceForm.price">: its ends, 0 and 1000.  applyEach(path.price, (value) => {    min(value, 0);    max(value, 1000);  }),);

Without a form — a live filter, a clip's trim, a chart's zoom — write them on the control instead, the same for every one:

<input scSlider [(value)]="volume" [min]="0" [max]="11" aria-label="Volume" /><div scRangeSlider [(value)]="clip" [min]="0" [max]="duration" aria-label="Trim">…</div>

Submitting

Bind the form to <form [formRoot]> and give it a submission action: on submit, every field is marked touched, the first invalid control takes the focus, and your action runs only once the form is valid.

readonly profileForm = form(this.profile, schema, {  submission: {    action: async () => this.api.save(this.profile()),  },});
// <form [formRoot]="profileForm">//   …fields…//   <button scButton type="submit">Save</button>// </form>