@vigdx/ui v2.2.0 on npm (opens in a new tab)

Form page

A routed create and edit page: sections in vig-card s, every field type, cross-field validation, an unsaved-changes guard with the Confirm service and a pending submit state, written in Reactive Forms, with the same form in Signal Forms.

Live demo

The recipe's page with its in-memory API. Change a field, then follow any link: the guard asks before your changes are lost. Saving a new project continues on its own URL.

Edit project

Basics

Client

Priority

Schedule and budget

Leave empty for an open-ended project.

Required for billable projects.

Billing and notes

Billable projects are invoiced against their budget.

Signal Forms variant

The same form built with form() and [formField] from @angular/forms/signals : same inputs, outputs and rules, no VigValueAccessor . Submit it to see the validation; a valid draft is announced in a toast.

Basics

Client

Priority

Schedule and budget

Leave empty for an open-ended project.

Required for billable projects.

Billing and notes

Billable projects are invoiced against their budget.

A routed page that creates and edits one record: /projects/new and /projects/:id . The form is split into sections, uses every common field type, validates across fields, protects unsaved changes and shows its submit state. It is written in Reactive Forms; the same form in Signal Forms sits next to it with the same contract, so pick the forms API your app uses.

When to use

  • Creating or editing a record that needs more room than a dialog: several sections, long text, dates, money.
  • The record has its own URL (deep links, back button, opening in a new tab).
  • Users may leave half-way, so unsaved changes need protection.
  • For three or four fields edited next to a list, use the dialog of the crud-list recipe instead.

Component choices

Need Component Why Alternatives
Sections vig-card with heading and headingLevel 2 Real headings structure the page for screen readers and the outline vig-accordion for optional sections; vig-stepper for a guided multi-step flow
Text vig-input ( maxLength , autocomplete ) Label, hint, error and counter wiring built in vig-autocomplete when the value comes from a list
Long text vig-input with multiline and autoResize Grows with the content instead of scrolling inside a box —
Money vig-number-input with currency Locale-aware parsing and formatting, null when empty Plain vig-input for codes that only look numeric (postal codes, IDs)
Choice of many vig-select with filter Six or more options, searchable vig-autocomplete for remote search
Choice of a few vig-radio-group horizontal Two to five options visible at once, native radios vig-select-button for a compact segmented look
Dates vig-date-picker ( clearable for optional ones) Calendar plus typing, a local-midnight Date Two pickers rather than a range picker when each end has its own rules
On/off setting vig-toggle-switch with hint Immediate, binary, explains its effect vig-checkbox for consent and agreement
Leaving with changes CanDeactivate guard + Confirm service The kit's confirmation dialog; works for every navigation in the app beforeunload (also used) only covers closing the tab
Feedback Toast service Success and failure without moving focus vig-message above the form for errors that block the user

Folder structure

Angular CLI

Text
src/app/features/projects/
  data-access/
    project.ts                   domain types and the date rule (endsBeforeStart)
    projects-api.ts              abstract API = DI token, ProjectNotFoundError
    http-projects-api.ts         HttpClient implementation (404 → ProjectNotFoundError)
    in-memory-projects-api.ts    seeded fake for demos and tests
    project-store.ts             signal store: open project, clients, saving
  feature/
    project-form-page.ts         routed smart page
    unsaved-changes-guard.ts     reusable CanDeactivate guard
    projects.routes.ts           /new and /:id
  ui/
    project-form-model.ts        form value type, mapping and labels
    project-form.ts              Reactive Forms variant
    project-signal-form.ts       Signal Forms variant

Wire it into src/app/app.routes.ts ; withComponentInputBinding() in provideRouter passes :id to the page's id input:

app.routes.ts
{
  path: 'projects',
  providers: [{ provide: ProjectsApi, useClass: HttpProjectsApi }],
  loadChildren: () =>
    import('./features/projects/feature/projects.routes').then((m) => m.projectsRoutes),
}

Nx

Terminal
npx nx g @nx/angular:library --directory=libs/projects/data-access --name=projects-data-access --tags=type:data-access,scope:projects --prefix=app --no-interactive
npx nx g @nx/angular:library --directory=libs/projects/feature-form --name=projects-feature-form --tags=type:feature,scope:projects --prefix=app --no-interactive
npx nx g @nx/angular:library --directory=libs/projects/ui --name=projects-ui --tags=type:ui,scope:projects --prefix=app --no-interactive

The guard is not specific to projects: once a second feature needs it, move it to a libs/shared/util-routing library ( type:util , scope:shared ).

Key decisions

  • One page for create and edit. The id input decides: new (or none) opens a blank form, an id loads the project. After a create the page navigates to the new project's URL with replaceUrl , so the back button does not return to an empty form; an edit replaces the loaded project in the store without a refetch.
  • The form is presentational. ProjectForm takes the project and the client options as inputs and emits a valid ProjectDraft ; the page saves it. Changing the project input resets the form, which also makes the saved values the new baseline. The page reads isDirty() for the guard.
  • Cross-field rules sit on the field to fix. "End date before start date" is a domain function in project.ts ; in Reactive Forms it is a validator on the end date that reads the sibling and re-runs when the start date changes. "Billable projects need a budget" adds or removes Validators.required on the budget whenever billable changes, so the field also gets the required marker and aria-required . The errors show under the end date (or budget), and focusFirstInvalid lands there. A group-level validator would leave no field marked invalid. In Signal Forms, validate() with valueOf() and required() with when express the same rules in the schema.
  • Dates are calendar days. The pickers work with local-midnight Date s; the API gets YYYY-MM-DD strings through the kit's toIsoDate and parseIsoDate , so no time zone shifts the day.
  • `errorDisplay` stays `'touched'`. Errors appear once a field is left, and every field is marked touched on a failed submit. A long form whose users tab through it first may prefer provideVigdxUi({ errorDisplay: 'interacted' }) (errors after an edit or a submit): the Reactive variant supports it as is, because VigValueAccessor mirrors the form's submitted flag; the Signal Forms variant submits through [formRoot] , whose <form> submit event the fields follow.
  • Reactive or Signal Forms. Both are stable in Angular 22 and the kit supports both. Reactive Forms needs VigValueAccessor next to the fields and valueChanges subscriptions for dependent rules; Signal Forms keeps the model in a signal, binds with [formField] and re-evaluates rules automatically. Use the one the rest of the app uses.
  • Submit state. The submit button shows loading while saving and a second submit is ignored; the button is never disabled up front, so users can always submit and learn what is missing.

Accessibility

  • The form is named by the page heading ( aria-labelledby ), each card title is an h2 , and every field has a visible label; required fields carry the kit's required marker.
  • A failed submit moves focus to the first invalid field; its error is linked with aria-describedby and announced once.
  • The guard's confirmation offers "Keep editing" as the safe choice; the native dialog returns focus to the link that was followed.
  • Loading shows skeletons inside a role="status" container with a name; not found and load errors use vig-empty-state headings, with a retry for errors; their texts are user-facing constants in PROJECT_FORM_PAGE_TEXT , never the technical error.message .
  • Radio buttons are native, so arrow keys and the single tab stop come from the browser.

Performance

  • The page and its forms are lazy-loaded with the feature routes; @angular/forms/signals is only in the bundle when the Signal Forms variant is used.
  • OnPush everywhere; options lists are computed , so they are rebuilt only when their input changes.
  • The client list loads once per page visit, in parallel with the project.

Definition of done

  • nx build <app> (or ng build ) succeeds; strict templates accept the [formField] bindings if you use Signal Forms.
  • nx lint passes, including module boundaries.
  • The specs pass: load for edit, not found, invalid submit focuses the first error, both cross-field rules, create navigates to the new URL, edit saves without a refetch, a failed save keeps the input, the guard asks only with unsaved changes.
  • axe reports no violations with errors showing, in light and dark mode.
  • Keyboard only: fill every field, submit, fix the errors, save, then edit and leave with changes.

Source files

Are you sure?