Socket
Book a DemoInstallSign in
Socket

aurelia2-forms

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aurelia2-forms

Form state and validation helpers for Aurelia 2

latest
Source
npmnpm
Version
0.0.1
Version published
Maintainers
1
Created
Source

aurelia2-forms

Form state and validation helpers for Aurelia 2. Provides:

  • <au-form> custom element
  • au-field custom attribute
  • FormController + FieldState models
  • Built-in validators
  • Integration with @aurelia/validation

Install

npm install aurelia2-forms

@aurelia/validation is a dependency of this package; register its configuration when you want rule-based validation.

Register

import { AureliaFormsConfiguration } from 'aurelia2-forms';
import { ValidationConfiguration } from '@aurelia/validation';

Aurelia.register(AureliaFormsConfiguration, ValidationConfiguration);

Quick start

<au-form submit.call="save($event)" form.bind="form">
  <input
    name="email"
    au-field="value.bind: email; validators.bind: [required(), email()]"
  />
  <button type="submit">Save</button>
</au-form>
import { FormController, required, email } from 'aurelia2-forms';

export class Page {
  email = '';
  form: FormController | null = null;

  save({ value }: { value: Record<string, unknown> }) {
    console.log(value);
  }
}

<au-form> API

Bindings:

  • submit.call or submit.bind: callback invoked after validation
  • validate-on-submit.bind (default true): run form.validate() on submit
  • form.bind: two-way binding to the FormController
  • validation-model.bind: object to validate with @aurelia/validation
  • validation-object-tag.bind: optional tag for ruleset selection

submit receives { form, value, event }.

<au-form> registers the FormController in DI so nested components can inject it:

import { IFormController } from 'aurelia2-forms';

export class Child {
  constructor(@IFormController private readonly form) {}
}

au-field API

au-field wires an input to a FieldState and synchronizes value + validation.

Bindings:

  • value.bind: two-way field value
  • validators.bind: array of validator functions
  • validate-on.bind: 'submit' | 'change' | 'blur' (default submit)
  • form.bind: attach to a specific form (optional)
  • validation-model.bind: override validation model (optional)
  • validation-property.bind: property name for rule-based validation (optional)

The field name defaults to the element's name attribute, then id, then "field". You can also set au-field="fieldName" if you want to set it explicitly.

Example:

<input
  name="firstName"
  au-field="value.bind: person.firstName; validate-on.bind: 'change'"
/>

Built-in validators

  • required()
  • email()
  • minLength(n) / maxLength(n)
  • min(n) / max(n)
  • pattern(regex)

Custom validators are simple functions:

import type { ValidatorFn } from 'aurelia2-forms';

const startsWithA: ValidatorFn<string> = (value) =>
  value?.startsWith('A') ? null : 'Must start with A';

FormController

FormController tracks aggregate state.

  • validate() -> Promise<boolean>
  • reset()
  • value (object of field values)
  • valid (boolean)
  • errors (map of field -> string[])
  • getField(name)

FieldState

FieldState exposes:

  • value, touched, dirty, errors, valid
  • validate()
  • reset()

@aurelia/validation integration

If you register ValidationConfiguration and pass a validation-model, field validation will also run Aurelia validation rules (in addition to local validators).

import { IValidationRules } from '@aurelia/validation';

validationRules.on(person).ensure('email').required();
<au-form validation-model.bind="person" form.bind="form">
  <input name="email" au-field="value.bind: person.email" />
</au-form>

If the field name does not match the model property, use validation-property:

<input
  name="emailAddress"
  au-field="value.bind: person.email"
  validation-property.bind="'email'"
/>

FAQs

Package last updated on 01 Jan 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts