المكوّنات · تحقّق داخل الحقل
تحقّق داخل الحقل
خطأ مربوط بحقله عبر aria-describedby، ويُعلَن مرّة واحدة
12 تصاميم من هذه العائلة
<div class="fb fbi"><form class="frm" novalidate>
<label><span data-ar="وزن المريض (كجم)" data-en="Patient weight (kg)">وزن المريض (كجم)</span>
<input class="wt" type="text" inputmode="decimal" aria-describedby="fbi-wt" dir="ltr">
<span class="msg" id="fbi-wt" aria-live="polite"></span></label>
<label><span data-ar="الجرعة المطلوبة (ملغ/كجم)" data-en="Dose (mg/kg)">الجرعة المطلوبة (ملغ/كجم)</span>
<input class="ds" type="text" inputmode="decimal" aria-describedby="fbi-ds" dir="ltr">
<span class="msg" id="fbi-ds" aria-live="polite"></span></label>
<div class="out"><span data-ar="الجرعة الكلّية" data-en="Total dose">الجرعة الكلّية</span>
<b class="tot num">—</b></div>
</form></div>
/* pt-scoped */
/* feedback-inline — نموذج طبّي */
.fbi{width:100%;height:100%;display:flex;flex-direction:column;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden}
.fbi h4{margin:0;font-size:11px;color:var(--pt-text-primary);font-weight:600;line-height:1.5}
.fbi p{margin:0;font-size:9px;line-height:1.85;color:var(--pt-text-muted)}
.fbi .num{font-variant-numeric:tabular-nums}
.fbi button{font:inherit;cursor:pointer}
.fbi button:focus-visible, .fbi input:focus-visible, .fbi a:focus-visible{
outline:2px solid var(--pt-focus-ring);outline-offset:2px}
.fbi button:disabled{cursor:not-allowed;opacity:.45}
/* كل حالة تُعلَن لقارئ الشاشة: تغيّرٌ لا يُرى ولا يُسمَع لم يحدث */
.fbi [role=status], .fbi [role=alert]{display:block}
@media(pointer:coarse){.fbi button{min-height:44px}
}
/* شخصية: نموذج ضيّق، رسائل تحت الحقول، انحناء صغير */
.fbi{align-items:center;justify-content:center;padding:12px}
.fbi .frm{display:flex;flex-direction:column;gap:8px;width:100%;max-width:250px}
.fbi label{display:flex;flex-direction:column;gap:3px}
.fbi label > span{font-size:8.5px;color:var(--pt-text-muted)}
.fbi input{padding:6px 9px;border-radius:var(--pt-radius-xs);
border:1px solid var(--pt-border-default);background:var(--pt-bg-inset);
font:inherit;font-size:10px;color:var(--pt-text-primary);outline:none;
font-variant-numeric:tabular-nums}
.fbi input[aria-invalid=true]{border-color:var(--pt-color-danger-400)}
.fbi input[aria-invalid=false]{border-color:color-mix(in srgb,var(--pt-accent) 50%,transparent)}
.fbi .msg{font-size:7.5px;min-height:10px;line-height:1.5}
.fbi .msg.bad{color:var(--pt-color-danger-400)}
.fbi .msg.warn{color:var(--pt-color-warn-400)}
.fbi .out{display:flex;align-items:baseline;justify-content:space-between;gap:8px;
padding:7px 10px;border-radius:var(--pt-radius-sm);background:var(--pt-bg-inset);
font-size:8.5px;color:var(--pt-text-muted)}
.fbi .out b{font-size:13px;color:var(--pt-accent);font-weight:700}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.fbi');
if (!host) return;
var snapshot = host.innerHTML;
var timers = [];
var ac = null;
/* الجسم كما كتبه المولِّد. يستقبل بدائل مظلَّلة لـ root وdocument
والمؤقّتات، فينظّف نفسه دون أن يعرف أنه قابل لإعادة التركيب. */
function run(root, document, setTimeout, setInterval) {
var ar = document.documentElement.lang !== 'en';
var n = function (v, d) { return Number(v).toLocaleString('en-US', {
minimumFractionDigits: d || 0, maximumFractionDigits: d || 0 }); };
var wt = root.querySelector('.wt'), ds = root.querySelector('.ds');
var tot = root.querySelector('.tot');
function digits(v) {
return String(v).replace(/[\u0660-\u0669]/g, function (d) { return d.charCodeAt(0) - 0x0660; })
.replace(/[^0-9.]/g, '');
}
var RULES = {
wt: { el: wt, min: 0.5, max: 300, unit: 'كجم',
bad: { ar: 'الوزن بين 0.5 و 300 كجم', en: 'Weight must be 0.5–300 kg' } },
ds: { el: ds, min: 0.1, max: 100, unit: 'ملغ/كجم',
bad: { ar: 'الجرعة بين 0.1 و 100 ملغ/كجم', en: 'Dose must be 0.1–100 mg/kg' } }
};
function num(el) { var v = parseFloat(digits(el.value)); return isNaN(v) ? null : v; }
function check(key, touched) {
var r = RULES[key], v = num(r.el);
var msg = r.el.parentElement.querySelector('.msg');
if (v === null) {
r.el.removeAttribute('aria-invalid');
msg.className = 'msg'; msg.textContent = ''; return null;
}
var ok = v >= r.min && v <= r.max;
r.el.setAttribute('aria-invalid', String(!ok));
msg.className = 'msg ' + (ok ? '' : 'bad');
msg.textContent = ok ? '' : (ar ? r.bad.ar : r.bad.en);
return ok ? v : null;
}
function refresh() {
var w = check('wt'), d = check('ds');
if (w === null || d === null) { tot.textContent = '—'; return; }
var total = w * d;
tot.textContent = n(total, 1) + (ar ? ' ملغ' : ' mg');
/* تحذير لا خطأ: القيمة صحيحة حسابيًّا لكنّها تستحقّ نظرة ثانية */
var msg = ds.parentElement.querySelector('.msg');
if (total > 2000) {
msg.className = 'msg warn';
msg.textContent = ar ? 'الإجمالي مرتفع — راجع البروتوكول' : 'Total is high — check the protocol';
}
}
[wt, ds].forEach(function (el) {
el.addEventListener('input', function () {
el.value = digits(el.value);
refresh();
});
});
wt.value = '72'; ds.value = '8';
refresh();
}
function mount() {
ac = new AbortController();
var real = window.document;
/* وسيط يمرّر كل شيء إلى المستند الحقيقي، ويعلّق كل مستمع بإشارة
تُقطع عند إعادة التركيب — فلا يبقى مستمع من نسخة ماتت. */
var doc = new Proxy(real, {
get: function (t, k) {
if (k === 'addEventListener') {
return function (type, fn, opts) {
var o = (opts && typeof opts === 'object') ? Object.assign({}, opts)
: { capture: !!opts };
o.signal = ac.signal;
return t.addEventListener(type, fn, o);
};
}
var v = t[k];
return typeof v === 'function' ? v.bind(t) : v;
}
});
function track(fn) {
return function (f, ms) { var id = fn(f, ms); timers.push(id); return id; };
}
run(host, doc, track(window.setTimeout.bind(window)),
track(window.setInterval.bind(window)));
}
function unmount() {
if (ac) ac.abort();
// المعرّفان يتشاركان فضاءً واحدًا في المتصفّح، فالإلغاء المزدوج آمن
timers.forEach(function (id) { window.clearTimeout(id); window.clearInterval(id); });
timers = [];
host.innerHTML = snapshot;
}
mount();
addEventListener('pt-lang', function () { unmount(); mount(); });
})();
# Inline Field Validation
**Role:** You are an Arabic-first UI designer and front-end engineer. Read the whole
specification before writing a single line, then follow it literally. If two requirements
conflict, favour usability over visual effect.
**Goal:** Inline Field Validation — An error bound to its field via aria-describedby, announced exactly once
**Why this component matters:** Bind the message to its input with aria-describedby and give it aria-live="polite" — an error that appears visually but is never announced leaves screen-reader users guessing why the form will not submit.
**Direction:** Genuine RTL — not a mirrored Latin layout. Use logical properties
(`margin-inline-start`, `padding-inline`, `inset-inline-start`, `text-align: start`),
never physical ones (`margin-left`, `left`). The layout must flip with `dir` on its own,
with no duplicated rules.
**Typography:** Cairo for Arabic, IBM Plex Sans for Latin. Arabic line-height must be
`0.18` higher than the Latin equivalent — dots, hamzas and maddas need more vertical room.
Arabic font-size runs `1.06×` the Latin size at the same optical weight.
**Numerals:** Western digits in both languages (`1,234.50`). Only the currency changes:
`ر.س` **after** the number in Arabic, `$` **before** it in English. Jordanian dinar
uses **three** decimal places, not two.
**Colors:** Dark mode — background `#0D142B` · surfaces `#211F54` · borders `#545C91` · text `#918FC2`.
Accent `#ADA9E8` must never exceed 8% of the screen area.
**Language:** Bilingual — every string carries both Arabic and English, and the layout
flips with `dir` automatically.
**States:** `default` · `hover` · `focus` · `active` · `disabled` · `loading` · `error`.
Do not design the resting state alone.
**Accessibility:** Contrast ratio at least `4.5:1`, complete keyboard navigation,
visible focus rings, and honour `prefers-reduced-motion`.
**Output:** Clean HTML and CSS in two separate files. No frameworks, no libraries,
no external dependencies.