buildField method presentation ✓ 94.4%
Last updated: 2026-03-04T23:21:38.384Z
Metrics
LOC: 61
Complexity: 25
Params: 1
Coverage: 94.4% (17/18 lines, 25x executed)
Signature
buildField(wrapper: HTMLElement): : FormField
Architecture violations
- [warning] max-cyclomatic-complexity: 'buildField' has cyclomatic complexity 25 (max 10)
Source Code
buildField(wrapper: HTMLElement): FormField {
const input = wrapper.querySelector<HTMLInputElement | HTMLTextAreaElement>(
"input, textarea",
);
// ant-input-number always wraps a numeric spinbutton — classify it directly
// so downstream classifiers never misidentify it as select or text.
const isInputNumber = wrapper.classList.contains("ant-input-number");
const nativeType =
input instanceof HTMLInputElement ? input.type : undefined;
const autocomplete =
input instanceof HTMLInputElement
? (input.getAttribute("autocomplete") ?? undefined)
: undefined;
// Only resolve fieldType for unambiguous native HTML types (confidence 1.0).
// Everything else stays "unknown" so TF.js / keyword / Chrome-AI classifiers
// can use contextSignals (label + name + placeholder + autocomplete) properly.
const resolvedFieldType = ((): FormField["fieldType"] => {
if (isInputNumber) return "number";
if (nativeType === "email") return "email";
if (nativeType === "tel") return "phone";
if (nativeType === "url") return "website";
if (nativeType === "password") return "password";
if (nativeType === "number") return "number";
if (nativeType === "date") return "date";
if (
nativeType &&
["time", "datetime-local", "month", "week"].includes(nativeType)
)
return "date";
return "unknown";
})();
const field: FormField = {
element: wrapper,
selector: getAntdSelector(wrapper),
category: "unknown",
fieldType: resolvedFieldType,
adapterName: "antd-input",
label: findAntLabel(wrapper),
name: findAntName(wrapper) ?? input?.name ?? undefined,
id: findAntId(wrapper) ?? input?.id ?? undefined,
placeholder: input?.placeholder || undefined,
// Expose autocomplete so buildSignals includes it in contextSignals,
// giving TF.js / keyword classifier a strong classification signal.
autocomplete: autocomplete || undefined,
required: isAntRequired(wrapper),
inputType: nativeType,
pattern:
input instanceof HTMLInputElement && input.pattern
? input.pattern
: undefined,
maxLength: input && input.maxLength > 0 ? input.maxLength : undefined,
minLength: input && input.minLength > 0 ? input.minLength : undefined,
};
field.contextSignals = buildSignals(field);
return field;
},
Dependencies (Outgoing)
| Target | Type |
|---|---|
| getAntdSelector | calls |
| findAntLabel | calls |
| findAntName | calls |
| findAntId | calls |
| isAntRequired | calls |
No incoming dependencies.