Canopy Date Input — Best Practices

SkillDev tools

Best practices for the Canopy Date Input component. Trigger when capturing or validating date values in a form in an Angular project using Canopy.

Available today. Use it from your connected AI after setup.

Connect ahel once, and every AI you use reads what you have installed.

Then ask your AI: use the Canopy Date Input — Best Practices skill

What this skill tells your AI

The instructions your AI receives, as published by legal-and-general/canopy in skills/best-practice/forms-date/SKILL.md and read by ahel’s review.

This skill provides usage guidance and input reference for the Canopy lg-date-field component from @legal-and-general/canopy.

Apply this skill whenever you use LgDateFieldComponent.


Import

import { LgDateFieldComponent } from '@legal-and-general/canopy';

Basic Usage

Use Angular reactive forms. Always include a #validationForm="ngForm" reference and a submit button inside the same <form>.

<form [formGroup]="form" (ngSubmit)="onSubmit()" #validationForm="ngForm">
  <lg-date-field formControlName="dateOfBirth">
    Date of birth
    @if (isControlInvalid(dateOfBirth, validationForm)) {
      <lg-validation>
        @if (dateOfBirth.hasError('invalidField')) {
          Enter a valid {{ dateOfBirth.errors.invalidField }}
        }
        @if (dateOfBirth.hasError('requiredField')) {
          Date of birth must include a {{ dateOfBirth.errors.requiredField }}
        }
        @if (dateOfBirth.hasError('invalidDate')) {
          Enter a valid date of birth
        }
        @if (dateOfBirth.hasError('required')) {
          Enter a date of birth
        }
      </lg-validation>
    }
  </lg-date-field>
  <button type="submit">Submit</button>
</form>

Using in a Child Component

When lg-date-field is in a child component with its own form group, inject ControlContainer and use formGroupName:

@Component({
  viewProviders: [
    { provide: ControlContainer, useExisting: FormGroupDirective },
  ],
})
export class ChildComponent {}
<ng-container formGroupName="childGroup">
  <lg-date-field formControlName="date">Date of birth</lg-date-field>
</ng-container>

Inputs

InputTypeDefaultDescription
dateIdstringauto-generatedid for the day input.
monthIdstringauto-generatedid for the month input.
yearIdstringauto-generatedid for the year input.
ariaDescribedBystringnullID of an element that describes the field. Always uses the hint component.
focusbooleannullSets focus on the fieldset.

Validation Error Priority

The component surfaces only the most significant error at a time:

PriorityError keyExample message
1invalidFieldEnter a valid month
1invalidFieldsEnter a valid month and year
2requiredFieldDate of birth must include a day
2requiredFieldsDate of birth must include a day and month
3invalidDateEnter a valid date of birth
4futureDateDate must be in the past
5requiredEnter a date of birth

Once the user fixes the first error, the next will surface automatically.


Design Constraints

  • The output value is a valid ISO 8601 date string: YYYY-MM-DD.
  • The component automatically adds an lg-hint — do not add a second one.
  • A #validationForm="ngForm" reference and a submit button must be present in the same <form> for validation to work correctly.

Signals

GitHub stars
23
Forks
46
Last commit
Sep 2026
Advanced
Catalog kind
skill
Gateway key
canopy-forms-date
Source
github.com/legal-and-general/canopy