All components (283)
Document (NIF, NIE, CIF)
Fields · DocumentField
What it is and when to use it
The NIF, the NIE or the CIF, with the control letter genuinely checked. 12345678A has the shape of a NIF and does not exist, because that number gets the Z: here it is checked, and the error says what is wrong ("The letter does not match the number") instead of an "invalid format" that helps nobody.
When to use it
- Customer sign-ups, billing details: any form that asks for a Spanish document. Each type with its own algorithm.
- What comes out through
onChangeis clean, without spaces, dots or hyphens, and in uppercase:12345678Z. errorfor whatever the server says (a NIF that already has an account): it takes precedence over the one the field calculates.
When not to
- A passport or the tax number of a country outside the EU:
TaxIdFieldorTextField. - Only an EU VAT number, without a Spanish document:
VatField. - A bank account:
IbanField.
EU VAT (euVat): the same field also takes the intra-community VAT number of the 27 member states and Northern Ireland. Anything starting with two letters is checked as a VAT number of its country, with its shape and check digit (the VatField rules); everything else, as a Spanish document. It suits a customer who may be from here or from another member state without asking for the country first. The help says "France VAT number is valid" and the error names the country.
Keyboard: that of a text field. The check fires on leaving the field, not on every key: marking a half-typed document in red is noise.
Accessibility: it is a TextField, with its label (by default "ID number"), its help and its error linked. When the document is valid, the help says so in words ("NIF is valid", "NIE is valid", "CIF is valid"), not with a color tick, and only if it really is, not if it "has the shape of" one.
Fine-tuning: no variables of its own: they are those of the field, --amset-field-*, with the digits in fixed width (amset-field--numeric).
What it looks like
<DocumentField label="NIF, NIE or CIF" hint="The invoice holder's" />
<DocumentField label="Company CIF" initialValue="B12345674" required />Props
Import it with import { DocumentField } from '@amset/ui'. Required props are marked.
| Prop | Type | What it does |
|---|---|---|
className | string | Merged with the library classes; it does not replace them. |
disabled | boolean | — |
error | string | Error from outside (from the server). It takes precedence over the one the field calculates. |
euVat | boolean | Also accepts the intra-community VAT number of the 27 member states and Northern Ireland (`FR40303265045`), checked country by country with its shape and check digit, like `VatField`. Anything starting with two letters is read as a VAT number; everything else, as a Spanish document. For a customer who may be from here or from another EU member state without asking for the country first. |
hint | string | — |
initialValue | string | — |
label | string | — |
onBlur | () => void | On leaving the field. The field already marks the error on leaving; this is to notify whoever uses it (a form). |
onChange | (value: string) => void | Arrives already clean and in uppercase: `12345678Z`. |
placeholder | string | Placeholder of the empty field. A sample NIF by default; `''` shows none (an empty field with a sample NIF reads like a saved value, and for a CIF it is also the wrong format). |
required | boolean | — |
size | "sm" | "md" | "lg" | — |
value | string | — |
variant | FieldVariant | — |
It also accepts the attributes of the element it renders: className, style, data-*, aria-* and its events.
In the test bench
Every state and variant, to try one at a time, on its page at storybook.amsetui.com:
