सुलभता पैटर्न · फ़ॉर्म
सुलभ फ़ॉर्म त्रुटियाँ काम करता पैटर्न · WCAG 2.2
एक डिलीवरी फ़ॉर्म जो लोगों को बताता है कि क्या गलत हुआ और उसे कैसे ठीक करें: फ़ोकस लेने वाला एक सारांश, हर फ़ील्ड के पास शब्दों में संदेश, और जो कुछ उन्होंने टाइप किया, उसमें से कुछ भी मिटाया नहीं जाता। इसे कीबोर्ड से आज़माएँ, फिर इसे चलाने वाला एचटीएमएल, सीएसएस और जावास्क्रिप्ट कॉपी करें।
- सफलता मानदंड
- 9
- लेवल
- A और AA
- ज़रूरी लाइब्रेरी
- कोई नहीं
- स्क्रिप्ट का आकार
- 8,257 B
आज़माएँ
गलतियों के साथ फ़ॉर्म भेजें
फ़ॉर्म खाली छोड़कर डिलीवरी विवरण सहेजें दबाएँ, या @ के बिना कोई ईमेल पता टाइप करें। फिर सारांश का कोई लिंक खोलें, वह फ़ील्ड ठीक करें और फ़ॉर्म फिर से भेजें।
डिलीवरी विवरण
लाइव फ़ॉर्म के लिए जावास्क्रिप्ट चाहिए। इसका कोड नीचे है, और इसके हर हिस्से को इसी पेज पर समझाया गया है।
यह क्या करती है
- भेजते समय जाँचता है, टाइप करते समय नहीं। आधा शब्द लिखते ही कुछ लाल नहीं होता।
- फ़ोकस को एक सारांश पर ले जाता है। उसमें हर समस्या होती है, और हर एक अपने फ़ील्ड का लिंक है।
- हर त्रुटि को उसके फ़ील्ड के पास समझाता है। शब्दों में, एक आइकन के साथ, फ़ील्ड से जुड़ा हुआ, ताकि स्क्रीन रीडर उसे वहीं पढ़े।
- बताता है कि उसे कैसे ठीक करें। “110001 जैसा 6 अंकों का पिन कोड डालें”, न कि “अमान्य इनपुट”।
- आपने जो टाइप किया, उसे रखता है। कुछ भी मिटाया नहीं जाता, और ठीक करते समय कुछ भी अपनी जगह से नहीं हिलता: संदेश तभी बदलते हैं जब आप फिर से भेजते हैं।
- सफलता बोलकर बताता है। स्टेटस मैसेज फ़ोकस हटाए बिना पढ़ा जाता है।
कोड
इसे चलाने वाला कोड कॉपी करें
ऊपर का फ़ॉर्म इन्हीं फ़ाइलों पर चलता है, ठीक वैसी ही जैसी साइट इन्हें भेजती है। अगर इस पेज का कोड और फ़ाइलें कभी अलग हुईं, तो एक टेस्ट फ़ेल हो जाता है।
<form class="afe" id="delivery" novalidate data-afe>
<!-- The summary: filled, shown and focused when the form is sent with errors.
Use the heading level that fits your page. -->
<div class="afe-summary" id="delivery-summary" tabindex="-1" hidden>
<h4 class="afe-summary__title">There is a problem with your details</h4>
<ul class="afe-summary__list"></ul>
</div>
<div class="afe-field">
<label class="afe-label" for="delivery-name">Full name <span class="afe-req">(required)</span></label>
<p class="afe-hint" id="delivery-name-hint">As it should appear on the parcel.</p>
<p class="afe-error" id="delivery-name-error" hidden></p>
<input class="afe-input" id="delivery-name" name="name" type="text" autocomplete="name" spellcheck="false" required aria-describedby="delivery-name-hint">
</div>
<div class="afe-field">
<label class="afe-label" for="delivery-email">Email address <span class="afe-req">(required)</span></label>
<p class="afe-hint" id="delivery-email-hint">We send updates about the delivery here.</p>
<p class="afe-error" id="delivery-email-error" hidden></p>
<input class="afe-input" id="delivery-email" name="email" type="email" autocomplete="email" spellcheck="false" required aria-describedby="delivery-email-hint">
</div>
<div class="afe-field">
<label class="afe-label" for="delivery-phone">Phone number <span class="afe-req">(optional)</span></label>
<p class="afe-hint" id="delivery-phone-hint">Only for the courier, if they cannot find you.</p>
<p class="afe-error" id="delivery-phone-error" hidden></p>
<input class="afe-input afe-input--short" id="delivery-phone" name="phone" type="tel" autocomplete="tel" aria-describedby="delivery-phone-hint">
</div>
<div class="afe-field">
<label class="afe-label" for="delivery-country">Country <span class="afe-req">(required)</span></label>
<p class="afe-error" id="delivery-country-error" hidden></p>
<!-- data-native keeps this site's custom dropdown off the select. Leave it out on yours. -->
<select class="afe-input" id="delivery-country" name="country" autocomplete="country" required data-native>
<option value="">Select a country</option>
<option value="CA">Canada</option>
<option value="IN">India</option>
<option value="GB">United Kingdom</option>
<option value="US">United States</option>
</select>
</div>
<div class="afe-field">
<label class="afe-label" for="delivery-postcode">Postcode <span class="afe-req">(required)</span></label>
<p class="afe-hint" id="delivery-postcode-hint">In India, your PIN code. In the United States, your ZIP code.</p>
<p class="afe-error" id="delivery-postcode-error" hidden></p>
<input class="afe-input afe-input--short" id="delivery-postcode" name="postcode" type="text" autocomplete="postal-code" spellcheck="false" required aria-describedby="delivery-postcode-hint">
</div>
<div class="afe-field">
<p class="afe-error" id="delivery-consent-error" hidden></p>
<div class="afe-check">
<input id="delivery-consent" name="consent" type="checkbox" value="yes" required>
<label for="delivery-consent">I agree that the courier may use these details to deliver my order <span class="afe-req">(required)</span></label>
</div>
</div>
<button class="afe-submit" type="submit">Save delivery details</button>
<p class="afe-status" role="status"></p>
</form>
/* Accessible form errors: the pattern's styles.
Colours are custom properties, so a site can point them at its own tokens.
Against --afe-bg, the defaults keep text at 4.5:1 or more and field
borders at 3:1 or more, in both colour schemes. */
.afe {
--afe-ink: #1b1b18;
--afe-ink-2: #4a4a44;
--afe-bg: #ffffff;
--afe-line: #6b6b64;
--afe-error: #b3261e;
--afe-ok: #146c3c;
display: grid;
gap: 1.25rem;
max-width: 34rem;
color: var(--afe-ink);
line-height: 1.5;
}
@media (prefers-color-scheme: dark) {
.afe {
--afe-ink: #f3f3ef;
--afe-ink-2: #c4c4bd;
--afe-bg: #1c1c1a;
--afe-line: #8f8f87;
--afe-error: #ff8a80;
--afe-ok: #7bd6a0;
}
}
.afe [hidden] { display: none !important; }
/* The summary: every error, as a link to its field. */
.afe-summary {
padding: 1rem 1.25rem;
border: 3px solid var(--afe-error);
border-radius: 8px;
scroll-margin-top: 6rem;
}
.afe-summary:focus { outline: 3px solid var(--afe-ink); outline-offset: 3px; }
.afe-summary__title { margin: 0 0 .5rem; font-size: 1.2rem; line-height: 1.3; }
.afe-summary__list { margin: 0; padding-left: 1.25rem; list-style: disc; }
.afe-summary__list li + li { margin-top: .3rem; }
.afe-summary__list a {
color: var(--afe-error);
font-weight: 600;
text-decoration: underline;
text-underline-offset: .15em;
}
/* A field: label, hint and error above the control. */
.afe-field { display: grid; gap: .3rem; }
.afe-field.is-invalid { padding-left: .9rem; border-left: 4px solid var(--afe-error); }
.afe-label { font-weight: 600; }
.afe-req { font-weight: 400; color: var(--afe-ink-2); }
.afe-hint { margin: 0; color: var(--afe-ink-2); }
.afe-error {
display: flex;
align-items: flex-start;
gap: .45rem;
margin: 0;
color: var(--afe-error);
font-weight: 600;
}
/* The icon is drawn in the text colour, so it stays visible in forced colours. */
.afe-icon {
display: inline-grid;
place-items: center;
flex: none;
box-sizing: border-box;
width: 1.3em;
height: 1.3em;
margin-top: .1em;
border: 2px solid currentColor;
border-radius: 50%;
font-size: .9em;
line-height: 1;
}
.afe-icon::before { content: "!"; font-weight: 800; }
.afe-input {
box-sizing: border-box;
width: 100%;
min-height: 2.75rem;
padding: .5rem .7rem;
border: 2px solid var(--afe-line);
border-radius: 6px;
background: var(--afe-bg);
color: var(--afe-ink);
font: inherit;
}
.afe-input--short { max-width: 14rem; }
.afe-input[aria-invalid="true"] { border-color: var(--afe-error); box-shadow: inset 0 0 0 1px var(--afe-error); }
/* The checkbox: a 24px box beside its label, so both are easy to hit. */
.afe-check { display: flex; align-items: flex-start; gap: .75rem; }
.afe-check input {
flex: none;
width: 1.5rem;
height: 1.5rem;
margin: 0;
accent-color: var(--afe-ink);
}
.afe-submit {
justify-self: start;
min-height: 2.75rem;
padding: .6rem 1.25rem;
border: 2px solid var(--afe-ink);
border-radius: 6px;
background: var(--afe-ink);
color: var(--afe-bg);
font: inherit;
font-weight: 700;
cursor: pointer;
}
.afe-input:focus-visible,
.afe-check input:focus-visible,
.afe-submit:focus-visible { outline: 3px solid var(--afe-ink); outline-offset: 2px; }
/* The status line stays rendered while empty: a live region that is not in
the page when its words arrive is not read out. */
.afe-status { margin: 0; color: var(--afe-ok); font-weight: 600; }
/* Read by screen readers, not shown. */
.afe-sr {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}
/**
* Accessible form errors: the behaviour.
*
* Enhances every <form data-afe>. The form is checked when it is sent, never
* while someone types. When anything is wrong:
* - each field in error gets its message in words, with an icon, next to it
* (joined to the field by aria-describedby), and is marked aria-invalid;
* - the summary at the top lists every message as a link to its field and
* takes focus, so a screen reader reads it straight away;
* - nothing that was typed is cleared.
* Messages change only when the form is sent again. Clearing one as someone
* leaves a field would move everything below it, and a click on the button
* that caused the leaving could then land somewhere else. When every field is
* valid, the status line says so (role="status": read out, focus stays put).
*/
import { FIELDS, SAVED, validate } from "./form-rules.js";
/** The form's values by field name. A box that is not ticked counts as "". */
function valuesOf(form) {
const values = {};
for (const name of FIELDS) {
const field = form.elements.namedItem(name);
if (!field) continue;
values[name] = field.type === "checkbox" ? (field.checked ? field.value : "") : field.value;
}
return values;
}
export function enhance(form) {
const summary = form.querySelector(".afe-summary");
const list = form.querySelector(".afe-summary__list");
const status = form.querySelector(".afe-status");
const fields = FIELDS.map((name) => form.elements.namedItem(name)).filter(Boolean);
// Each field's own description (its hint), so an error can be added to it and taken off again.
const hints = new Map(fields.map((field) => [field, field.getAttribute("aria-describedby") || ""]));
function showError(field, message) {
const box = document.getElementById(`${field.id}-error`);
const hint = hints.get(field);
field.closest(".afe-field")?.classList.toggle("is-invalid", Boolean(message));
if (!message) {
box.replaceChildren();
box.hidden = true;
field.removeAttribute("aria-invalid");
if (hint) field.setAttribute("aria-describedby", hint);
else field.removeAttribute("aria-describedby");
return;
}
const icon = document.createElement("span");
icon.className = "afe-icon";
icon.setAttribute("aria-hidden", "true");
const prefix = document.createElement("span");
prefix.className = "afe-sr";
prefix.textContent = "Error:";
const words = document.createElement("span");
words.textContent = message;
box.replaceChildren(icon, prefix, " ", words);
box.hidden = false;
field.setAttribute("aria-invalid", "true");
field.setAttribute("aria-describedby", `${hint} ${box.id}`.trim());
}
function summaryLink(field, message) {
const item = document.createElement("li");
const link = document.createElement("a");
link.href = `#${field.id}`;
link.textContent = message;
item.append(link);
return item;
}
// A link in the summary shows its field with the label above it, then moves focus there.
summary.addEventListener("click", (event) => {
const link = event.target.closest("a[href^='#']");
const field = link && document.getElementById(link.getAttribute("href").slice(1));
if (!field) return;
event.preventDefault();
(field.closest(".afe-field") || field).scrollIntoView({ block: "center" });
field.focus({ preventScroll: true });
});
form.addEventListener("submit", (event) => {
// This example sends nothing. A real form sends the data at the end of
// this handler (with fetch), or stops the browser only when there are
// errors and lets it submit; either way, the server checks it again.
event.preventDefault();
const errors = validate(valuesOf(form));
for (const field of fields) showError(field, errors.find((e) => e.name === field.name)?.message || "");
status.textContent = "";
if (errors.length) {
list.replaceChildren(...errors.map((e) => summaryLink(form.elements.namedItem(e.name), e.message)));
summary.hidden = false;
summary.focus();
return;
}
list.replaceChildren();
summary.hidden = true;
// Written a moment after it was emptied, so a second success is read out too.
setTimeout(() => { status.textContent = SAVED; }, 100);
});
}
if (typeof document !== "undefined") {
for (const form of document.querySelectorAll("form[data-afe]")) enhance(form);
}
/**
* Accessible form errors: the rules.
*
* Pure functions with no DOM, so they run (and are tested) anywhere. Each rule
* takes a field's value, and all the values for rules that depend on another
* field, and returns "" when the value is fine or the message to show when it
* is not. Every message says what to do, not only what is wrong (WCAG 3.3.3),
* and the same words appear in the summary and beside the field.
*/
/** The fields in the order they appear, so errors are listed in that order. */
export const FIELDS = ["name", "email", "phone", "country", "postcode", "consent"];
/** What the form says when every field is valid. */
export const SAVED = "Your delivery details are complete. This example sends nothing: they stay on this page.";
/** Postcode formats for the countries the form offers. Spaces and case are forgiven. */
export const POSTCODES = {
CA: { re: /^[A-Z][0-9][A-Z] ?[0-9][A-Z][0-9]$/, message: "Enter a Canadian postal code, like K1A 0B1" },
IN: { re: /^[1-9][0-9]{2} ?[0-9]{3}$/, message: "Enter a 6-digit PIN code, like 110001" },
GB: { re: /^[A-Z]{1,2}[0-9][A-Z0-9]? ?[0-9][A-Z]{2}$/, message: "Enter a UK postcode, like EC1A 1BB" },
US: { re: /^[0-9]{5}(-[0-9]{4})?$/, message: "Enter a 5-digit ZIP code, like 10001, or a ZIP+4 code, like 10001-1234" },
};
/** Collapse runs of spaces and trim: what people type is not what they mean to be checked. */
const tidy = (value) => String(value ?? "").replace(/\s+/g, " ").trim();
export const RULES = {
// Names have no reliable format, so the only check is that one was given.
name(value) {
return tidy(value) ? "" : "Enter your full name";
},
email(value) {
const v = tidy(value);
if (!v) return "Enter your email address";
if (!v.includes("@")) return "Enter an email address with an @, like [email protected]";
const [, domain = ""] = v.split("@");
if (!domain.includes(".")) return "Enter the part after the @, like [email protected]";
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(v)) return "Enter an email address in the right format, like [email protected]";
return "";
},
// Optional: an empty phone number is fine, a wrong one is not.
phone(value) {
const v = tidy(value);
if (!v) return "";
if (!/^\+?[0-9 ().-]+$/.test(v)) return "Use only digits, spaces, brackets and hyphens, with + only at the start";
const digits = v.replace(/[^0-9]/g, "").length;
if (digits < 7 || digits > 15) return "Enter a phone number with 7 to 15 digits, or leave it empty";
return "";
},
country(value) {
return POSTCODES[tidy(value)] ? "" : "Select the country for delivery";
},
postcode(value, values = {}) {
const v = tidy(value).toUpperCase();
if (!v) return "Enter your postcode";
const format = POSTCODES[tidy(values.country)];
// Without a country there is no format to check against; the country has its own error.
return !format || format.re.test(v) ? "" : format.message;
},
consent(value) {
return value ? "" : "Select the box to agree that the courier may use these details";
},
};
/** Every problem with a set of values, in field order: [{ name, message }]. */
export function validate(values = {}) {
const errors = [];
for (const name of FIELDS) {
const message = RULES[name](values[name], values);
if (message) errors.push({ name, message });
}
return errors;
}
- मार्कअप और स्टाइल जोड़ें। id आपस में मेल खाते रखें: हर फ़ील्ड के संकेत और त्रुटि की id उसकी अपनी id के बाद “-hint” और “-error” जोड़कर बनती है।
- स्क्रिप्ट को मॉड्यूल के रूप में, नियमों वाली फ़ाइल के साथ लोड करें। यह data-afe वाले हर फ़ॉर्म को बेहतर बनाती है, और इसे कुछ और नहीं चाहिए।
<script type="module" src="form-errors.js"></script> - नियमों में अपने संदेश लिखें। मान सही होने पर हर नियम कुछ नहीं लौटाता, वरना एक वाक्य लौटाता है जो बताता है कि क्या करना है।
- सर्वर पर फिर से जाँचें। जावास्क्रिप्ट के बिना ब्राउज़र फ़ॉर्म भेज देता है, इसलिए सर्वर को वही सारांश और संदेश, भरे हुए मानों के साथ, वापस भेजने चाहिए।
क्या गलत होता है
वही फ़ॉर्म, आम तरीके से बना
यह संस्करण वे गलतियाँ करता है जो कई असली फ़ॉर्म में मिलती हैं। इसे खोलें, इसमें टाइप करें, गलतियों के साथ भेजें, और तुलना करें।
यह जान-बूझकर फ़ेल होता है, इसलिए जब तक आप इसे न खोलें, यह बंद रहता है। वही फ़ील्ड, वही जाँचें: सिर्फ़ मार्कअप और त्रुटियाँ दिखाने का तरीका अलग है।
टूटे हुए संस्करण को अपनी त्रुटियाँ दिखाने के लिए जावास्क्रिप्ट चाहिए।
इसमें क्या गलत है
- लेबल की जगह प्लेसहोल्डर। टाइप करते ही हर फ़ील्ड का नाम गायब हो जाता है, इसलिए आप नहीं जाँच सकते कि कोई बॉक्स किस लिए था। 3.3.2
- त्रुटियाँ सिर्फ़ लाल रंग में। सिर्फ़ बॉर्डर का रंग बदलता है और कुछ नहीं, इसलिए जो लोग लाल रंग नहीं देख पाते, और स्क्रीन रीडर उपयोगकर्ता, उन्हें नहीं बताया जाता कि कौन-सा फ़ील्ड गलत है। 1.4.1 3.3.1
- एक अस्पष्ट संदेश, जो किसी चीज़ से नहीं जुड़ा। “फ़ॉर्म में एक गड़बड़ी है” यह नहीं बताता कि कहाँ या क्या, और इसकी घोषणा भी नहीं होती। 3.3.3
- हर की दबाने पर जाँच। ईमेल बॉक्स पहले ही अक्षर पर लाल हो जाता है, किसी के उसे पूरा करने से पहले ही।
- कोई autocomplete टोकन नहीं। सहेजा हुआ पता भरने से पहले ब्राउज़र को अंदाज़ा लगाना पड़ता है कि हर बॉक्स किस लिए है। 1.3.5
एक स्वचालित जाँच इसे पास कर देती है। axe-core 4.12.1 को खोले गए और गलतियों के साथ भेजे गए टूटे संस्करण में कोई उल्लंघन नहीं मिला: ब्राउज़र प्लेसहोल्डर को फ़ील्ड का नाम मान लेते हैं, और कोई टूल यह नहीं बता सकता कि लाल रंग ही त्रुटि का अकेला संकेत है। इसीलिए कीबोर्ड और स्क्रीन रीडर से जाँच ज़रूरी है।
स्क्रीन रीडर के क्या कहने की उम्मीद है
मार्कअप और एआरआईए व एचटीएमएल विनिर्देशों से निकाला गया, स्क्रीन रीडर से रिकॉर्ड नहीं किया गया। सटीक शब्द हर स्क्रीन रीडर में अलग होते हैं।
| पल | यह पैटर्न | टूटा हुआ संस्करण |
|---|---|---|
| Tab से पहले फ़ील्ड पर जाना | “पूरा नाम (ज़रूरी), एडिट, ज़रूरी”, फिर संकेत “जैसा पार्सल पर लिखा होना चाहिए।” | “पूरा नाम, एडिट”: प्लेसहोल्डर नाम का काम करता है, और टाइप करते ही स्क्रीन से गायब हो जाता है। |
| गलतियों के साथ फ़ॉर्म भेजना | फ़ोकस सारांश पर जाता है, इसलिए उसका शीर्षक और समस्याओं की सूची पढ़ी जाती है। | कुछ नहीं। फ़ोकस बटन पर ही रहता है, और ऊपर वाले संदेश की घोषणा नहीं होती। |
| त्रुटि वाले फ़ील्ड पर पहुँचना | लेबल, “अमान्य एंट्री”, फिर संकेत और “त्रुटि: अपना पूरा नाम डालें”। | सिर्फ़ प्लेसहोल्डर वाला नाम। लाल बॉर्डर की घोषणा नहीं होती। |
| सही फ़ॉर्म भेजना | “आपके डिलीवरी विवरण पूरे हैं…”, स्टेटस मैसेज से पढ़कर सुनाया जाता है। | कुछ नहीं, जब तक व्यक्ति खुद न ढूँढे। |
WCAG 2.2
यह किन चीज़ों पर लागू होता है
वे सफलता मानदंड जिन्हें यह फ़ॉर्म पूरा करता है, और कैसे।
इन्हें पूरा करने वाला फ़ॉर्म पेज का एक हिस्सा भर है। बाकी पेज को भी इन्हें पूरा करना होता है, और तब भी यह अपने आप में अनुरूपता का दावा नहीं है।
सभी डब्ल्यूसीएजी मानदंड| मापदंड | स्तर | यह फ़ॉर्म इसे कैसे पूरा करता है |
|---|---|---|
| 1.3.1 जानकारी और संबंध | A | हर लेबल for और id एट्रिब्यूट से अपने फ़ील्ड से जुड़ा है; संकेत और त्रुटियाँ aria-describedby से जुड़ी हैं; सारांश एक शीर्षक और एक सूची है। |
| 1.3.5 इनपुट का उद्देश्य पहचानें | AA | व्यक्ति से जुड़े फ़ील्ड में autocomplete टोकन हैं: name, email, tel, country और postal-code। |
| 1.4.1 रंग का उपयोग | A | त्रुटि शब्दों में, एक आइकन और मोटे बॉर्डर व पट्टी के साथ दिखाई जाती है, कभी सिर्फ़ रंग से नहीं। |
| 3.2.2 इनपुट पर | A | टाइप करने या कोई मान चुनने से पेज पर और कुछ नहीं बदलता; जाँच तब चलती है जब आप बटन दबाते हैं। |
| 3.3.1 त्रुटि पहचान | A | त्रुटि वाला हर फ़ील्ड aria-invalid से चिह्नित है और उसके पास व सारांश में टेक्स्ट में बताया गया है। |
| 3.3.2 लेबल या निर्देश | A | स्क्रीन पर बने रहने वाले दिखते लेबल, ज़रूरी और वैकल्पिक शब्दों में बताए गए, और फ़ॉर्मैट के लिए संकेत। |
| 3.3.3 त्रुटि सुझाव | AA | हर संदेश बताता है कि समस्या कैसे ठीक करें, और जहाँ कोई फ़ॉर्मैट अपेक्षित है वहाँ एक उदाहरण देता है। |
| 4.1.2 नाम, भूमिका, मान | A | नेटिव इनपुट, एक नेटिव select और एक नेटिव चेकबॉक्स, हर एक का नाम उसके लेबल से, और ज़रूरी व अमान्य स्थितियाँ उजागर। |
| 4.1.3 स्टेटस मैसेज | AA | सफलता का संदेश एक role="status" क्षेत्र है, जो फ़ोकस लिए बिना पढ़ा जाता है। |
जो यह फ़ॉर्म पूरा नहीं करता
- 3.3.4 त्रुटि निवारण (क़ानूनी, वित्तीय, डेटा): डिलीवरी फ़ॉर्म किसी को किसी बात के लिए बाध्य नहीं करता। भुगतान या ऑर्डर के लिए जाँचने का एक चरण, या उसे वापस लेने का तरीका चाहिए।
- 3.3.7 दोहराई गई एंट्री: लंबी प्रक्रिया में, व्यक्ति ने जो पहले से दिया है उसे खुद भरें, जैसे बिलिंग पता।
- 2.4.11 फ़ोकस अवरुद्ध नहीं (न्यूनतम): एक स्टिकी हेडर या कुकी बैनर अब भी उस फ़ील्ड को छिपा सकता है जिस पर सारांश का लिंक ले जाता है; अपने पेज पर जाँचें।
- 1.4.3 कंट्रास्ट (न्यूनतम): डिफ़ॉल्ट रंग जाँचे गए हैं, पर आप जो रंग बदलकर लगाएँ, उन्हें जाँचना आपका काम है।
टेस्टिंग नोट्स
इसे कैसे परखा गया
क्या जाँचा गया, किससे, और क्या नहीं।
4 अक्टूबर 2026 को Chromium में जाँचा गया, नीचे दिए कीबोर्ड चरण एक स्क्रिप्ट से चलाए गए।
कीबोर्ड, एक-एक चरण
- फ़ॉर्म के ऊपर से Tab दबाएँ। फ़ोकस पूरा नाम, ईमेल पता, फ़ोन नंबर, देश, पोस्टकोड, चेकबॉक्स और फिर डिलीवरी विवरण सहेजें पर जाता है।
- हर फ़ील्ड खाली रखकर किसी भी टेक्स्ट फ़ील्ड में Enter दबाएँ, या बटन पर Space।
- फ़ोकस सारांश पर जाता है। उसमें पाँच समस्याएँ हैं; फ़ोन नंबर वैकल्पिक है, इसलिए वह उनमें से एक नहीं है।
- पहले लिंक, अपना पूरा नाम डालें, तक पहुँचने के लिए Tab दबाएँ, और Enter दबाएँ। फ़ोकस पूरा नाम फ़ील्ड में जाता है, और उसका लेबल दिखता रहता है।
- कोई नाम टाइप करें और फ़ॉर्म फिर से भेजने के लिए Enter दबाएँ। फ़ोकस सारांश पर लौटता है, जिसमें अब चार समस्याएँ हैं; पूरा नाम के पास का संदेश हट चुका है।
- बाकी भरें, Space से बॉक्स पर टिक करें, और फ़ॉर्म फिर से भेजें। सफलता का संदेश दिखता है और फ़ोकस बटन पर ही रहता है।
- Shift+Tab दबाकर फ़ॉर्म में वापस जाएँ। आपने जो कुछ टाइप किया, सब वहीं है।
स्क्रीन रीडर: क्या उम्मीद करें
- अभी NVDA, JAWS, VoiceOver या TalkBack से नहीं परखा गया। ऊपर की तालिका में अपेक्षित घोषणाएँ मार्कअप से निकाली गई हैं, किसी रिकॉर्डिंग से नहीं।
- विवरण (संकेत और त्रुटि) आम तौर पर लेबल और स्थिति के बाद, एक छोटे ठहराव के बाद पढ़े जाते हैं।
- सारांश की घोषणा इसलिए होती है क्योंकि वह फ़ोकस लेता है। उसमें role="alert" नहीं है, इसलिए उसे दो बार नहीं पढ़ा जाना चाहिए।
स्वचालित जाँच
- axe-core 4.12.1: इस पेज पर कोई उल्लंघन नहीं: फ़ॉर्म खाली होने पर, गलतियों के साथ भेजने के बाद और सही भेजने के बाद, लाइट और डार्क थीम में, 1280 और 390 पिक्सेल चौड़ाई पर।
- Playwright ऊपर के कीबोर्ड चरण चलाता है और हर चरण पर फ़ोकस, aria-invalid, aria-describedby, सारांश के लिंक और स्टेटस मैसेज जाँचता है।
- यूनिट टेस्ट form-rules.js के हर नियम को सही और गलत मानों पर चलाते हैं, और जाँचते हैं कि इस पेज का कोड फ़ाइलों से बाइट-दर-बाइट मेल खाता है।
ज्ञात सीमाएँ
- “ज़रूरी” हर लेबल में भी है और required एट्रिब्यूट में भी, इसलिए कुछ स्क्रीन रीडर इसे दो बार बोलते हैं। अगर आपकी टेस्टिंग में यह बाधा बने, तो एक हटा दें।
- पोस्टकोड के फ़ॉर्मैट सिर्फ़ चार देशों के लिए जाँचे जाते हैं, और नाम सिर्फ़ इसलिए कि वे भरे गए हों: लोगों के नाम किसी नियम पर नहीं चलते।
- कोड में संदेश अंग्रेज़ी में हैं। इस साइट पर हिंदी पेज उनका अनुवाद करता है; अपनी साइट पर उनका अनुवाद form-rules.js में करें।
- ब्राउज़र में जाँच एक सुविधा है, सुरक्षा नहीं। सर्वर को फिर से जाँचना ही चाहिए।
डिज़ाइन के फ़ैसले
यह इस तरह क्यों काम करता है
पैटर्न के पीछे के फ़ैसले, ताकि आप इसे अपने हिसाब से ढाल सकें।
फ़ॉर्म भेजते समय क्यों जाँचें, टाइप करते समय क्यों नहीं?
आधे शब्द पर दिखने वाली त्रुटि गलत होती है, ध्यान भटकाती है, और व्यक्ति के टाइप करते समय ही पढ़ी जा सकती है। भेजते समय जाँचने से एक साफ़ पल मिलता है जिसमें सारी समस्याएँ एक साथ दिखती हैं। संदेश भी अगली बार भेजने तक बने रहते हैं: फ़ील्ड छोड़ते समय किसी संदेश को हटाने से उसके नीचे का सब कुछ खिसक जाता, और बटन पर किया गया क्लिक गलत जगह पड़ सकता था।
एक सारांश और हर फ़ील्ड के पास संदेश, दोनों क्यों?
सारांश बताता है कि कितनी समस्याएँ हैं और आपको हर एक तक ले जाता है। फ़ील्ड के पास का संदेश वह है जो आप उसे ठीक करते समय पढ़ते हैं, और जो स्क्रीन रीडर आपके वहाँ पहुँचने पर पढ़ता है। दोनों में वही शब्द हैं, इसलिए उन्हें मिलाना आसान है।
फ़ोकस पहले फ़ील्ड पर नहीं, सारांश पर क्यों ले जाएँ?
पहले फ़ील्ड पर पहुँचने से आपको एक समस्या का पता चलता है। सारांश पर पहुँचने से सभी का, और हर एक बस एक लिंक दूर है। छोटे फ़ॉर्म में पहले फ़ील्ड पर जाना भी ठीक विकल्प है।
सारांश पर role="alert" क्यों नहीं?
फ़ोकस सारांश पर ले जाने से स्क्रीन रीडर उसे पहले ही पढ़ देता है। उसके ऊपर alert लगाने से वह दो बार पढ़ा जा सकता है। alert तभी इस्तेमाल करें जब फ़ोकस न हिल सके, जैसे जब त्रुटियाँ सर्वर से तब आएँ जब व्यक्ति पेज पर कहीं और हो।
फ़ॉर्म सही होने तक बटन बंद क्यों न रखें?
ज़्यादातर ब्राउज़र में बंद बटन पर फ़ोकस नहीं जा सकता, और वह यह नहीं बताता कि वह बंद क्यों है। लोग अंदाज़ा लगाते रह जाते हैं कि कौन-सा फ़ील्ड गलत है। समस्याओं की सूची से जवाब देने वाला चालू बटन उन्हें बता देता है।
ब्राउज़र के अपने त्रुटि बबल क्यों न इस्तेमाल करें?
वे एक बार में एक त्रुटि दिखाते हैं, कुछ सेकंड में गायब हो जाते हैं, हर फ़ील्ड के लिए उनकी स्टाइल या शब्द नहीं बदले जा सकते, और हर ब्राउज़र व स्क्रीन रीडर उन्हें अलग तरह से संभालता है। फ़ॉर्म उन्हें novalidate से बंद करता है, पर required, type और autocomplete रखता है, जो सहायक तकनीक को अब भी बताते हैं कि हर फ़ील्ड क्या है।
अगला
अपने फ़ॉर्म जाँचें
वे चेकलिस्ट आइटम जिनका जवाब यह पैटर्न देता है, पेज स्कैन करने का एक टूल, और जो मिले उसे लिखने का एक टेम्पलेट।
- चेकलिस्टहर कंट्रोल का एक प्रोग्रामैटिक लेबल है
- चेकलिस्टत्रुटियों की पहचान टेक्स्ट में होती है और वे फ़ील्ड से जुड़ी होती हैं
- यूआरएल एनालाइज़रकिसी पेज में छूटे लेबल, autocomplete टोकन और बहुत कुछ स्कैन करें
- ऑडिट टेम्पलेटगंभीरता, ज़िम्मेदार और दोबारा जाँच के साथ निष्कर्ष लिखें
इन मानदंडों के अलग-अलग लाइव डेमो: 3.3.1 त्रुटि पहचान, 3.3.2 लेबल या निर्देश, 3.3.3 त्रुटि सुझाव और 1.3.5 इनपुट का उद्देश्य पहचानें.
स्रोत
यह कहाँ से आया है
ऑरिक आर्टिज़न ने लिखा और परखा। अभी किसी स्वतंत्र सुलभता विशेषज्ञ ने इसकी समीक्षा नहीं की है।
इस पेज की कोई समस्या बताएँ- वेब सामग्री सुलभता दिशानिर्देश (डब्ल्यूसीएजी) 2.2w3.org
- W3C WAI फ़ॉर्म ट्यूटोरियल: उपयोगकर्ता को सूचनाw3.org
- तकनीक G139: ऐसा तरीका बनाना जिससे उपयोगकर्ता सीधे त्रुटियों पर जा सकेंw3.org
- तकनीक ARIA21: त्रुटि वाले फ़ील्ड को बताने के लिए aria-invalid का उपयोगw3.org
- तकनीक G177: सुधार के लिए सुझाया गया टेक्स्ट देनाw3.org
- तकनीक ARIA22: स्टेटस मैसेज दिखाने के लिए role=status का उपयोगw3.org
- डब्ल्यूसीएजी 2.2, खंड 7: यूज़र इंटरफ़ेस कंपोनेंट के लिए इनपुट उद्देश्यw3.org
कोई ग़लती मिली? हमें लिखें और हम उसे ठीक करेंगे।