isValueValidForElement function ✓ 91.7%
Last updated: 2026-02-24T21:07:57.586Z
Metrics
LOC: 40
Complexity: 11
Params: 3
Coverage: 91.7% (11/12 lines, 24x executed)
Signature
isValueValidForElement(
element: ValueConstraints["element"],
value: string,
): : boolean
Architecture violations
- [warning] max-cyclomatic-complexity: 'isValueValidForElement' has cyclomatic complexity 11 (max 10)
Source Code
function isValueValidForElement(
element: ValueConstraints["element"],
value: string,
): boolean {
if (!element) return true;
// Custom component wrappers (div, span, etc.) are not native form elements.
// Skip the validity probe and trust the adapter to accept any generated value.
if (
!(element instanceof HTMLInputElement) &&
!(element instanceof HTMLTextAreaElement) &&
!(element instanceof HTMLSelectElement)
) {
return true;
}
if (element instanceof HTMLSelectElement) {
return true;
}
if (
element instanceof HTMLInputElement &&
(element.type === "checkbox" ||
element.type === "radio" ||
element.type === "file")
) {
return true;
}
const probe = element.cloneNode(false) as
| HTMLInputElement
| HTMLTextAreaElement;
try {
probe.value = value;
return probe.checkValidity();
} catch {
return false;
}
}
No outgoing dependencies.
Impact (Incoming)
| Source | Type |
|---|---|
| adaptGeneratedValue | calls |