All jobs

Add Form Validation to a Vue App

Yes. An agent adds client-side validation to your sign-in, sign-up, settings and editor forms in the same error shape your API returns, tests it, and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent reads how the forms submit and how errors are shown before it adds rules, so the new messages look like the ones users already see. In an app shaped like realworld-apps/vue-realworld-example-app, package.json has vue ^3.5, vue-router ^5.1 and pinia ^3.0, no validation library, bun.lock as the lockfile, and scripts for vite, eslint src, prettier --check and playwright test. src/views/Login.vue and src/views/Register.vue bind email, password and username with v-model, call authStore.login or authStore.register on submit, and render errors from the Pinia store in a ul.error-messages through formatError in src/common/format.js. src/views/Settings.vue and src/views/ArticleEdit.vue keep a local errors ref filled by extractErrors in src/common/errors.js and render it with src/components/ListErrors.vue. Every error, from the server or from a network failure, is an object of { field: [messages] }, the RealWorld API's shape. None of the inputs has a required, type="email" or minlength attribute, so an empty form goes to the API and comes back with a server error.

It adds src/common/validation.js with small pure functions that return messages in that same shape: validateLogin({ email, password }), validateRegister({ username, email, password }), validateSettings(form) and validateArticle(article). The rules are the ones the API enforces and the forms imply: a required email that looks like an address, a required password, a required username, an image URL that parses when it is not blank, and an article with a title, a description and a body. Because the result has the shape { email: ["can't be blank"] }, ListErrors.vue and the formatError loops render client-side messages exactly as they render server ones, with no new component.

Each view calls its validator in the submit handler before touching the store. Login.vue and Register.vue set authStore.errors to the result and return when it is not empty, so the existing errors list shows the message and no request is sent; Settings.vue and ArticleEdit.vue set their local errors ref the same way. The inputs also get type="email", required, autocomplete and aria-invalid bound to whether that field has an error, so browsers and screen readers get the same information, and the novalidate attribute on each form keeps the browser's own bubbles from competing with the list. Script setup, ref and reactive, double quotes and semicolons follow what the views already use, so bun run lint and bun run format:check pass without reformatting.

The e2e suite lives in the realworld submodule, so the agent does not add specs there. It adds a test:unit script that runs bun test, the runner bun ships with, and writes src/common/validation.test.js: an empty login form reports both fields, a malformed email reports only email, a valid article reports nothing, and a blank image is accepted. No new dependency is needed. It then runs bun run lint, bun run format:check, bun run build and bun run test:e2e so the Playwright specs in realworld/specs/e2e, which sign in and publish articles against the real app, still pass with validation in front of them.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Add client-side form validation to this Vue app and open a pull request. Read package.json, src/views/Login.vue, src/views/Register.vue, src/views/Settings.vue, src/views/ArticleEdit.vue, src/store/auth.js, src/store/article.js, src/common/errors.js, src/common/format.js, src/components/ListErrors.vue, playwright.config.ts and the workflows in .github/workflows first. Add src/common/validation.js with pure functions that return errors in the API's { field: [messages] } shape for login, register, settings and the article editor, and call them in each view's submit handler before the store, showing the result through the error list each view already renders. Add type, required, autocomplete and aria-invalid attributes to the inputs and novalidate to the forms. Do not add a validation library. Add a test:unit script that runs bun test and write src/common/validation.test.js. Keep the existing code style. Run bun run lint, bun run format:check, bun run build, bun run test:unit and bun run test:e2e and paste the results in the pull request. Do not change the stores or the API service.",
  "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 adds src/common/validation.js and src/common/validation.test.js, edits the four views' templates and submit handlers, and adds one script to package.json. The stores, api.service.js and ListErrors.vue are untouched. The description lists each form's rules, shows the error object a blank sign-in produces, and pastes the lint, format, build, unit and Playwright output.

On a repository with the Format Check and Playwright Tests workflows, the pull request runs Prettier and ESLint, then installs Chromium and runs bun run test:e2e against the dev server on port 8080, so a validator that rejects a value the e2e specs submit fails in CI before review.

A reviewer checks that the rules match what their API accepts, in particular the password length and username characters, since the client should never refuse something the server allows. Then they decide whether to show errors on blur as well as on submit; the validators return per-field results, so wiring a watch on a field is a small follow-up.

Run it on every Vue app whose forms only validate on the server

A team with several Vue front ends sends one POST /o/{org}/sessions per repository with this prompt and that repository in resources. Each run reads its own forms and error rendering, so an app that already shows errors under each field gets per-field messages and an app with VeeValidate installed gets rules in that library's style, and each run opens its own pull request.

Give the API key a webhook_url and Rush POSTs run.completed when each turn ends, with the session_url to read the pull request and the test output from.

The use case this job follows, with its automation and trigger: Hand off a long task.

Why run it on Rush?

Client-side validation goes wrong in two directions: rules that are looser than the server's and let bad input through, or rules that are stricter and refuse input the server would accept, locking real users out. The second kind is invisible in a code read. In a Rush sandbox the agent runs the repository's own Playwright specs, which sign up, sign in and publish articles through the real forms, with the validation in front of them, and keeps every command and its output in the run's record, so the pull request shows the existing flows still complete.

The validators return the same { field: [messages] } object the API returns, so the error list, the formatting helper and the store's errors state all work unchanged, and a message from the client reads like a message from the server. There is no library to add, no schema language to learn, and the unit tests run on the runtime the repository already uses.

Frequently asked questions

Why not use VeeValidate or Vuelidate?

The forms have a handful of required fields and one email rule, and the app already has a way to render { field: [messages] } errors. A few pure functions cover it with no dependency and no change to the templates' structure. The pull request notes that a library is a fine choice when the forms grow, and the validators' shape makes that switch local.

Does the server still validate?

Yes. The client checks run first and stop an obviously bad request, but every submission that passes still goes to the API, and its errors are shown through the same list. Client validation is a convenience for the user, not a security boundary.

Where do the unit tests run if there is no Jest or Vitest?

On bun test, the test runner bundled with bun, which the repository already uses for installs and for the Playwright and release workflows. The agent adds a test:unit script for it and a validation.test.js beside the module. No test library is installed.

Why are the Playwright specs not extended?

They live in the realworld git submodule, shared across RealWorld front ends, so this repository cannot change them. The agent runs them to show the sign-in and publish flows still pass, and covers the validators themselves with unit tests in this repository.

More Vue jobs

The same job on other stacks

Keep reading