पेज·मुफ़्त
साइन-अप फ़ॉर्म (Vue)
TypeScript में Vue 3 सिंगल-फ़ाइल कंपोनेंट के रूप में साइन-अप फ़ॉर्म, जिसमें नाम, ईमेल और पासवर्ड हैं। किसी फ़ील्ड से हटने पर यह बताता है कि क्या गलत है, और स्क्रीन रीडर भी वही संदेश सुनाते हैं। कोई लाइब्रेरी नहीं; रंग CSS वैरिएबल से आते हैं।
मुफ़्त में इंस्टॉल करें।
अगर आपके Android डिवाइस पर PocketCode इंस्टॉल है, तो यह पेज ऐप में खुलेगा।
प्रीव्यू
SignupForm.vue · 211 लाइनें
<!--
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"यह प्रीव्यू छोटा किया गया है। पूरा कंटेंट इंस्टॉल करने पर मिलेगा।
1.0.0 में बदलाव
पहला संस्करण।