pickstack

Angular + Yup

Schema validation with a chainable API (Yup 1.7+, a Standard Schema). This page shows exactly what pickstack adds to a Angular project for Yup: the packages, the new files and the changes to existing ones. Every combination is installed, built, linted and tested in CI.

$ npm create pickstack@latest my-app -- --framework angular --modules tanstack-form,yup --yes
Customize in the configurator

Packages it adds

PackageVersionType
@tanstack/angular-form^1.33.5runtime
yup^1.7.1runtime

New files

src/app/components/signup-form/signup-form.html
@if (joined()) {
  <p class="text">Thanks, {{ joined() }} is on the list.</p>
} @else {
  <form novalidate class="form" (submit)="submit($event)">
    <ng-container [tanstackField]="form" name="email" #email="field">
      <label class="field">
        Email
        <input
          type="email"
          class="input"
          [name]="email.api.name"
          [value]="email.api.state.value"
          (blur)="email.api.handleBlur()"
          (input)="email.api.handleChange($any($event.target).value)"
        />
        @if (errors()[0]; as error) {
          <span role="alert" class="error">{{ error.message }}</span>
        }
      </label>
    </ng-container>
    <button type="submit" class="btn">Sign up</button>
  </form>
}
src/app/components/signup-form/signup-form.ts
import { Component, signal } from "@angular/core";
import { injectForm, injectStore, TanStackField } from "@tanstack/angular-form";
import { object, string } from "yup";

const schema = object({
  email: string()
    .required("Enter a valid email address.")
    .email("Enter a valid email address."),
});

@Component({
  selector: "app-signup-form",
  imports: [TanStackField],
  templateUrl: "./signup-form.html",
})
export class SignupForm {
  protected readonly joined = signal("");
  protected readonly form = injectForm({
    defaultValues: { email: "" },
    validators: { onSubmitAsync: schema },
    onSubmit: ({ value }) => this.joined.set(value.email),
  });
  // The template reads errors through a signal, so it updates without zone.js.
  protected readonly errors = injectStore(
    this.form,
    (state) => state.fieldMeta.email?.errors ?? [],
  );

  protected submit(event: SubmitEvent): void {
    event.preventDefault();
    void this.form.handleSubmit();
  }
}

Changes to existing files

src/app/pages/about/about.html (changed)
 <section class="page">   <h1 class="title">About</h1>+  <p class="text">Built with Angular 22, TypeScript, TanStack Form, Yup.</p>−  <p class="text">Built with Angular 22, TypeScript.</p> </section>  
src/app/pages/home/home.html (changed)
 <section class="page">   <h1 class="title">my-app</h1>   <app-counter />+  <app-signup-form /> </section>  
src/app/pages/home/home.ts (changed)
 import { Component } from "@angular/core"; import { Counter } from "../../components/counter/counter";+import { SignupForm } from "../../components/signup-form/signup-form";   @Component({   selector: "app-home",+  imports: [Counter, SignupForm],−  imports: [Counter],   templateUrl: "./home.html", }) export class Home {}⋯ 1 unchanged lines
src/styles.css (changed)
⋯ 87 unchanged lines   background: #334155; }  +.form {+  display: flex;+  width: 100%;+  max-width: 24rem;+  flex-direction: column;+  gap: 0.75rem;+}+ +.field {+  display: flex;+  flex-direction: column;+  gap: 0.25rem;+  font-size: 0.875rem;+  font-weight: 500;+}+ +.input {+  border: 1px solid #cbd5e1;+  border-radius: 0.5rem;+  padding: 0.5rem 0.75rem;+  font: inherit;+}+ +.error {+  color: #dc2626;+  font-weight: 400;+}+ 

Project files

Related templates