# Add Form Validation to an Angular App

Yes. An agent adds validators and per-field messages to your sign-in, sign-up, settings and editor forms, keeps the API error list, tests them, and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-form-validation/angular/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the forms as they are before it adds a rule. In an app shaped like realworld-apps/angular-realworld-example-app, `package.json` pins `@angular/forms` 21.2.12 beside `@angular/core`, runs `vitest` for `test` through `@analogjs/vite-plugin-angular`, `playwright test` for `test:e2e`, `prettier --check` for `format:check`, and installs with `bun`. `src/app/core/auth/auth.component.ts` builds a typed `FormGroup<AuthForm>` whose `email` and `password` controls carry only `Validators.required`, adds a `username` control with the same single rule when the route ends in `register`, and its template disables the submit button with `[disabled]="!authForm.valid"`, so an empty form cannot be sent but a malformed email can. The `email` input is `type="text"`.

`src/app/features/settings/settings.component.ts` is the odd one: `image`, `username`, `bio` and `email` have no validators at all, while `password` is `Validators.required`, even though `submitForm` deletes an empty password from the payload. That means a user who only wants to change their bio is blocked until they type a password. `src/app/features/article/pages/editor/editor.component.ts` types `articleForm` as `UntypedFormGroup`, gives `title`, `description` and `body` no rules, and publishes with a `type="button"` click rather than a form submit. All four pages show server errors through `src/app/shared/components/list-errors.component.ts`, which flattens an `Errors` object of `{ errors: { field: message } }` into `<li>` items in a `ul.error-messages`.

The agent adds rules that match what the RealWorld API already rejects: `Validators.email` on every email control, `Validators.minLength(8)` on passwords where one is being set, `Validators.minLength(3)` and `Validators.maxLength(20)` on `username`, `Validators.required` on the editor's `title`, `description` and `body`, and it removes `required` from the settings password so the field means "new password, optional". It turns the editor form into a typed `FormGroup<ArticleForm>`, moves the publish button to `type="submit"` with `(ngSubmit)`, and marks every control touched on submit with `markAllAsTouched()` so the messages appear at the moment a user expects them. The messages render in the same `ul.error-messages` list as the API's, from a small `formErrors` helper that turns `{ email: { required: true } }` into `email can't be blank`, the exact phrasing the backend uses, so a page never shows two styles of error.

Tests go where the repository already runs them. The suite today has six `*.spec.ts` files, all for services, under `vitest.config.ts` with `jsdom` and `src/test-setup.ts`. The agent adds `auth.component.spec.ts`, `settings.component.spec.ts` and `editor.component.spec.ts` that render each standalone component with `TestBed`, provide a stubbed `UserService` and `ArticlesService`, set invalid values, submit, and assert both that the service was not called and that the expected `<li>` text is in the DOM; a passing case asserts the call happened once with the form's value. It runs `bun run test`, `bun run format:check` and `bun run build`, and runs the Playwright suite from the `realworld` submodule, whose specs fill the forms with valid data, to show that nothing in the shared RealWorld flow changed.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add client-side form validation to this Angular app and open a pull request. Read package.json, vitest.config.ts, src/app/core/auth/auth.component.ts and .html, src/app/features/settings/settings.component.ts and .html, src/app/features/article/pages/editor/editor.component.ts and .html, src/app/shared/components/list-errors.component.ts and src/app/core/models/errors.model.ts first. Keep reactive forms and the existing error list. Add Validators.email to email controls, minLength(8) to passwords that are being set, minLength(3) and maxLength(20) to username, and required to the editor's title, description and body. Make the settings password optional. Type the editor form group and submit it through ngSubmit. Show validation messages in the same ul.error-messages list, phrased like the API's errors, after markAllAsTouched on submit. Add Vitest component specs for the three pages covering an invalid submit that does not call the service and a valid one that does. Run bun run test, bun run format:check, bun run build and bun run test:e2e, and paste their output in the pull request.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request that edits the three component classes and their templates, adds a `form-errors.ts` helper under `src/app/shared`, and adds three component specs. The description lists each rule per field, shows the settings password change as its own paragraph because it changes behaviour a user can notice, and pastes the Vitest summary, the Prettier check, the production build with its bundle budget line, and the Playwright summary.

The repository's `Format Check` and `Playwright Tests` workflows run on the pull request, so the checks a reviewer sees are the ones already configured; the Vitest run is in the description because no workflow runs it yet.

A reviewer checks that the messages read like the API's own, that the sign-up button is still disabled on an empty form, that a settings save with an empty password still succeeds, and that the editor no longer publishes an article with an empty title. They merge when the three new specs and the end-to-end suite are green.

## Run it on every Angular app whose forms only validate on the server

A team with several Angular front ends sends one `POST /o/{org}/sessions` per repository, with this prompt and that repository in `resources`. Each run reads its own forms, so an app that already uses `Validators.email` gets only the rules it lacks, and each opens a pull request on its own branch.

Send a `request_id` with each call so a retried request returns the run already started instead of a second pull request, and set a `webhook_url` on the key so `run.completed` reaches your server with `session_url` when each turn ends.

## Why run it on Rush?

Validation is a job of a dozen small edits across forms, templates and specs, and the proof is running the whole suite, including a Playwright run that needs a browser and the dev server at port 4200. In a Rush sandbox the agent installs with `bun`, starts `ng serve`, runs the shared RealWorld specs against it, and keeps every command and its output in the run's record beside the pull request.

On a laptop this is an afternoon of context switching between four pages. The agent does it in one pass with the repository's own tools, and because the sandbox parks when the turn ends, a follow-up such as "also validate the image URL on settings" wakes the same checkout and adds to the same pull request.

## Frequently asked questions

### Why not add a validation library?

The app already uses `@angular/forms` reactive forms with typed controls, and every rule this job needs is in `Validators`. Adding a library would add a dependency to `package.json` and a second way to express rules. The helper that turns validation errors into messages is a few lines in `src/app/shared`.

### Does the server still validate?

Yes. The client rules stop obvious mistakes before a request is sent; the API still answers `422` with its `errors` object, and `ListErrorsComponent` still shows it. The agent phrases the client messages the same way so a user cannot tell which side produced one.

### Why change the settings password rule?

Because `settings.component.ts` already drops an empty password from the payload in `submitForm`, the `Validators.required` on it only blocks users who want to change something else. Making it optional, with a minimum length when it is filled, matches what the submit code intended.

### Will the Playwright suite still pass?

The specs in the `realworld` submodule fill every form with valid values, so the new rules do not fire in them. The agent runs `bun run test:e2e` after the change and pastes the summary; if a spec depended on submitting an empty field, the pull request says so rather than editing the shared suite.

## More Angular jobs

- [Add i18n to an Angular App](https://getrush.ai/run/add-i18n/angular/)
- [Add a Not Found Page to an Angular App](https://getrush.ai/run/add-not-found-page/angular/)
- [Add Optimistic UI to an Angular App](https://getrush.ai/run/add-optimistic-ui/angular/)

## The same job on other stacks

- [Add Form Validation to a React Router App](https://getrush.ai/run/add-form-validation/react-router/)
- [Add Form Validation to a SolidJS App](https://getrush.ai/run/add-form-validation/solidjs/)
- [Add Form Validation to a Vue App](https://getrush.ai/run/add-form-validation/vue/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
