Skip to content
Page·Free

Sign-up form (Vue)

A sign-up form for Vue 3 as a single-file component in TypeScript, with name, email and password. When you leave a field, it says what is wrong, and screen readers announce the same message. It uses no libraries, and the colours come from CSS variables.

Free to install.

If PocketCode is installed on your Android device, this opens the page in the app.

Preview

SignupForm.vue · 211 lines
<!--
  Sign-up form for Vue 3 (script setup + TypeScript), with no libraries.
  Each field says what is wrong under it after you leave it or press "Create account",
  and screen readers hear the same message. The parent gets the values in `submit`:

    <SignupForm :pending="saving" @submit="createAccount" />

  Colours come from CSS variables with fallbacks: set --form-text, --form-muted,
  --form-border, --form-error, --form-primary-bg and --form-primary-text to match your app.
-->
<script setup lang="ts">
import { computed, reactive, ref, useId } from 'vue';

export interface SignupValues {
  name: string;
  email: string;
  password: string;
}

const props = withDefaults(defineProps<{ pending?: boolean; minPassword?: number }>(), {
  pending: false,
  minPassword: 8,
});

const emit = defineEmits<{ submit: [values: SignupValues] }>();

const id = useId();
const values = reactive<SignupValues>({ name: '', email: '', password: '' });
const touched = reactive({ name: false, email: false, password: false });
const showPassword = ref(false);

const errors = computed(() => ({
  name: values.name.trim() ? '' : 'Enter your name.',
  email: /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(values.email.trim()) ? '' : 'Enter an email like [email protected].',
  password:
    values.password.length >= props.minPassword ? '' : `Use at least ${props.minPassword} characters.`,
}));

type Field = keyof SignupValues;

function errorFor(field: Field): string {
  return touched[field] ? errors.value[field] : '';
}

function onSubmit() {
  touched.name = touched.email = touched.password = true;
  const firstBad = (['name', 'email', 'password'] as const).find((f) => errors.value[f]);
  if (firstBad) {
    document.getElementById(`${id}-${firstBad}`)?.focus();
    return;
  }
  emit('submit', { name: values.name.trim(), email: values.email.trim(), password: values.password });
}
</script>

<template>
  <form class="signup" novalidate :aria-busy="pending" @submit.prevent="onSubmit">
    <h2 class="title">Create your account</h2>

    <div class="field">
      <label :for="`${id}-name`">Name</label>
      <input
        :id="`${id}-name`"
        v-model="values.name"
        type="text"
        autocomplete="name"
        :aria-invalid="!!errorFor('name')"
        :aria-describedby="errorFor('name') ? `${id}-name-error` : undefined"
        @blur="touched.name = true"
      />
      <p v-if="errorFor('name')" :id="`${id}-name-error`" class="error">{{ errorFor('name') }}</p>
    </div>

    <div class="field">
      <label :for="`${id}-email`">Email</label>
      <input
        :id="`${id}-email`"
        v-model="values.email"
        type="email"
        inputmode="email"

This preview is shortened. You get the full content when you install it.

Changes in 1.0.0

First version.

Related

Contact form (HTML + CSS)FreePageA contact form in one HTML file: name, email, an optional topic and the message. Every field has a label, and a red border appears only after someone types in it or tries to send. Set the form's action to your endpoint. Dark mode follows the system.Login screen (Compose)FreePageEmail and password screen in Material 3. It checks both fields when you tap Sign in, shows the error your server returns, and can add Forgot password and fingerprint buttons. You call BiometricPrompt yourself.Settings screen (Compose)FreePageMaterial 3 settings screen with switches, a theme choice and a text size slider. It holds no state: you pass a SettingsState in and get the changed copy back. Each row is one touch target of 56 dp or more that TalkBack reads as a switch or radio button.FAQ with search (Svelte)FreePageA FAQ section for Svelte 5 in TypeScript. The search box filters questions as you type, and two buttons open or close all the answers. It is built on details elements, so keyboard and screen reader support comes from the browser.Async button (Vue)FreeButtonA Vue 3 button that runs an async action. While it waits it shows a spinner and ignores extra taps. It emits done or error, so you decide what to show next. Written in TypeScript with no libraries.Sign-in screen (Flutter)FreePageA Material 3 sign-in screen for Flutter. It checks the email and password, can show or hide the password, supports autofill and shows a spinner while it signs in. Colours come from your app's theme, and it needs only the Flutter SDK.