@fieldia/widgets
v0.36.1
Published
Fieldia field inputs in plain DOM, with the underline and outlined skins.
Readme
@fieldia/widgets
The field inputs of Fieldia, in plain DOM: text, numbers,
choices, ratings and scales, dates, many2one search pickers, tags, tables of
lines, file and image uploads (as a list, thumbnails, or cards with each name
under its picture), formatted text and JSON. Three skins, chosen per
form with data-fd-skin:
underline— labels beside values, quiet underlined inputs (a business sheet)outlined— labels above boxed inputs (Ant Design style)quiet— the outlined page, each value plain words until pointed at or entered (Azure DevOps style); a field the viewer marksdata-quietwears it in any skin, andwearsQuiet(field, node)says which widgets do
npm install @fieldia/widgetsThe widgets' own words (WIDGET_LABELS) come in English, Arabic, German and
French, and in Turkish, Persian, Urdu and Spanish — machine-assisted, not yet
reviewed by a native speaker, each of those four in a chunk of its own,
fetched where it is spoken (wordsReady in @fieldia/core, which the viewer
awaits before it draws); a number box on a Persian or Urdu page reads
their digits (۰–۹), and a Turkish page's date box writes a day with dots
(15.10.2026), as a German one does. On a page right to left, every value a
person typed reads in its own direction, lined up with the page — an English
note on an Arabic order keeps its full stop at its end — in its box, a table's
cell and card, a list's cell, a read view and on paper: one rule.
Most apps never import this package directly: @fieldia/viewer
lays a page out with these widgets. Import it to write your own widget — a
WidgetFactory returns { element, update(state), focus() } — and register it
with the viewer's widgets option under type or type.widget.
A widget that draws from its own state alone — its value, read-only, required,
invalid, what describes it, and of the form only its field's text left unread,
its choices and their places — says so with reads: the other fields whose
values it shows besides (a money box its currency's field), [] for none. The
viewer then leaves it alone while none of that changed, so a key typed elsewhere
on a page of 500 fields costs it nothing. Left out, it is brought up to date at
every change, as before; a widget that reads values whole, parent or anything
else of the form leaves it out.
A widget that throws — as it is drawn, brought up to date, focused or taken away —
never takes the page with it: createWidget puts a small box in its place ("This
field could not be shown: Price", in the page's language, said to a screen reader
as a status), tells the context's onError (the console when there is none), and
leaves the widget alone from then on. A widget that learns of its own failure
later — a framework's component caught by its binding — calls context.fail(error).
What a page uses only now and then comes in parts, each loaded the first time a
page shows it (datePart, linesPart, choicePart, …): the viewer waits for a
page's parts before it draws it (loadParts in @fieldia/viewer). A widget
drawn before its part came is drawn plainly, keeps its value and what is typed
in it, and the part's own takes its place. One whose part cannot come stays
plain, and works, and tells its field (context.unloaded(part, retry): the
viewer says so under it, with Retry, which asks for the part again and puts its
widget in place as it comes). A link to other records —
many2oneWidget, tagsWidget, linkCheckboxesWidget, referenceWidget,
charTagsWidget — comes in relationsPart (fieldia.relations.js beside the
script bundle): meanwhile a many2one is a plain box whose words are handed to
the part's box as typed, or, left first, looked up by their exact name as the
part's box would; a many2many's tags are their names beside a box to add one.
floatUnder(box, list) floats a list under its box over everything else, as
the links' and the choices' lists float, for a widget of your own.
Where the data source has upload, a file or picture field stores each file as
it is picked and shows it on its way: its picture, a bar that fills, where it
is in words, × to cancel it, Retry when it failed — in a list, on cards and on
thumbnails, right to left and dark. Photos are made smaller first by the field's
shrink ({ maxSide, quality }, or false), their EXIF turn kept;
shrinkPhoto(file, { maxSide, quality }) does the same for your own code.
A film or a sound in a file field plays in the browser's own player: among the
files a film shows its poster frame under a play mark — the app's own picture,
the value's poster, else the film's frame half a second in — and plays in the
dialog from that frame; a sound in a list plays where it is, its player under
its name (a voice note listened to in place). Its kind is its media type, else,
where none is known, its extension. One the browser cannot play says so.
A file field whose node says "options": { "record": "audio" } (or "video",
or both) records a voice note or a short film on the page: Record beside its
picker opens the recorder over the form — the browser asks for the microphone
(and the camera), a refusal is said with Try again, then Start, the time against
maxSeconds (120 for a voice note, 60 for a film unless it says) and Stop — and
the recording, played back, is used as a file picked is: through the data
source's upload where it has one. The recorder comes in recordPart
(fieldia.record.js), loaded the first time Record is pressed; where the browser
cannot record (a page not served over https), the buttons are not shown.
Every box says what the browser may fill it in with and which keyboard a phone
shows for it: the field node's autocomplete (a purpose from the HTML
standard's list, such as given-name, work email or shipping postal-code,
or off) and inputmode (numeric, decimal, tel, email, url,
search, text) over its kind's own — an email box email, a phone tel, a
web address url, a password new-password, a whole number's digits, an
address's parts each its own after whose it is ("autocomplete": "shipping"):
{ "type": "field", "id": "f-code", "field": "code", "autocomplete": "one-time-code" }boxPurpose(node, own) gives the same attributes to a widget of your own. A
value the browser fills in is the person's own, read as typed: cleaned as a
paste is, never put back where nobody may be looking, read at once in a box the
person is not in, and saved as any change of theirs.
Text dropped into a box is judged where it lands, as a paste is: cleaned, or
refused and said, at the place it was let go. To place your own drag data in a
box — a palette's {{ name }} — call preventDefault() on its drop, on the box
or anything round it: the box then takes nothing of that drop.
A one-line text box trims its ends as it is left (its spaces, and direction
marks at its ends); "options": { "trim": false } keeps them as typed, for words
whose ends matter — a template's "New: " before a field is dragged in.
A value is shown as a code to scan with "widget": "qrcode" (a char or text
field: a QR code, its words as UTF-8, at options.level L, M, Q or H) or
"widget": "barcode" (a char or integer field: Code 128), drawn as SVG from the
value — black on white, crisp on paper, named for a screen reader — under the
field's own box while it may be typed in; size and showValue set its size
and the words under it. A barcode's value is an identifier, said as it is — a
number never grouped, in its box at rest too; a QR code's is said by
codeSummary: a short line as it is, else a link with parameters by its
address, a contact card or a Wi-Fi network by its name, or nothing (the code
alone, named "QR code"). Words a code cannot hold are said in its place. The
encoders are Fieldia's own, in codesPart (fieldia.codes.js):
(await codesPart.load()).qrCode(words, 'M'), .code128(words).
Pins with notes go on a picture with "widget": "pins" on a json field — a
face chart, a floor plan, a car's damage: options.image (its address) or
options.imageField (a field holding it), alt, maxPins, noteLabel. The
value is the pins, [{ "x": 0.42, "y": 0.31, "note": "Botox, 4 units" }], each
as shares of the picture's width and height from its top left. A click or a tap
puts a pin, a pin is dragged, and the keyboard does both (a cross moved by the
arrows, Enter; on a pin, the arrows, Delete); the pins are a numbered list under
the picture for a screen reader. It comes in pinsPart (fieldia.pins.js).
A phone field ("widget": "phone") is read the world over where its page says
"phone": { "country": "EG", "shown": "national" } — or the field itself, with
"options": { "country": "AE" } or "shown". Its country is picked before the
number — its flag and dialling code, pressed to open a list of every country
found by typing its name in the page's language or in English, its code ("ae")
or its dialling code ("+971"), the page's country and the reader's first, a
sheet on a phone ("countries": "native" puts the browser's own list there) —
or typed with it: "010 1234 5678" is read in the country picked,
"+20 10 1234 5678" or "0020…" in Egypt whatever was picked. The number is
checked by its country — how long it is by how it starts, and whether any number
there starts so — kept as E.164 ("+201012345678"), and shown at rest abroad's
way ("+20 10 1234 5678", the default) or at home's ("010 1234 5678"), a call
link beside it, and a WhatsApp link where it may be a mobile — by how its
country's mobiles start (canBeMobile): Cairo's 02 2537 4100 is called, its
010… also chatted with; where a country's mobiles cannot be told from its fixed
lines (+1's), any number may be one. A letter is refused and said why; a number
that does not read stays as typed with why ("too short for a +20 number
(Egypt)", or, letters typed, "letters are not allowed in a phone number"), and
the save refuses it. No country is ever assumed: without one, a number is
written with its +. A page that says neither keeps its phone fields as text
boxes. The country table (phoneCountries, readPhone, writePhone,
shownPhone) comes in the phone part with the widget,
(await phonePart.load()).readPhone('010 1234 5678', 'EG').
A date and time is shown and typed on its time zone's clock — its own
timeZone, or its page's — with the zone's short name beside its box where
the browser's zone is another ("CEST"), and after it in words ("15 Oct 2026,
14:30 CEST"), which a paste reads back. A time the clocks skip on a change
day is said, never moved ("there is no 02:30 on 29 Mar 2026 in Central European
Time: the clocks go from 02:00 to 03:00"); one they repeat asks which, naming
both offsets ("write 02:30 +02:00 or 02:30 +01:00"), and is read once either
offset, or the zone's short name ("02:30 CEST"), is typed after it. A
table's cell, a list's, and a value read-only write a date and time as its box
does: the instant it is, on the browser's clock where nothing names a zone —
never the clock it was written with (12:30Z is 15:30 to a person in Cairo).
A date of a month alone — a billing period, a card's expiry — is
"precision": "month" on its field, and of a year alone — a building's year —
"precision": "year". Its box takes a month as people write one — 10/2026,
10-2026, 2026-10, Oct 2026, أكتوبر ٢٠٢٦, octobre 2026 — or four digits, keeps
its first day ("2026-10-01", "2026-01-01") and shows it at rest in the
page's language ("Oct 2026", "2026"); its button opens a year's twelve months,
or twelve years. A whole day typed or pasted gives its month, and the day it
leaves out is said. Its min and max are kept by the month or the year: with
"min": "today", this month is still within it. A list's cell and a value
read-only write it the same way.
"first_rent": { "type": "date", "label": "First rent's month", "precision": "month", "min": "today" }A date with "hijri": true is shown and typed in the Hijri calendar beside
the Gregorian day it keeps, by Umm al-Qura's reckoning as the browser's Intl
keeps it (islamic-umalqura): a second box beside its own reads "2 Jumada I
1448 AH" at rest ("2 جمادى الأولى 1448 هـ" in Arabic) and 02/05/1448 while it
is typed in, in the page's order; a day typed in either box writes the other.
A Hijri month has 29 or 30 days as Umm al-Qura says, and a day past them is
said with the days it has, kept unread in its own box while the field holds the
day it held. Its calendar shows each day's Hijri day under it, and the Hijri
months a month spans in its title; a list's cell writes both days ("13 Oct
2026 · 2 Jumada I 1448 AH"). The value stays the Gregorian day, as every
backend keeps it. Both come in the date part with the date box.
A choice's options may say more than their words — "caption", a second line
under them (a service's length and price), "icon", one of Fieldia's icons by
name (or the app's), and "color", #rrggbb, a dot beside them. Radios and
checkboxes draw them (option-look.ts); a dropdown whose options have any is
Fieldia's own list, never the browser's, which shows one line; a list that
searches draws them too. A link's suggestions draw what the data source gives
of each record: its picture, or its colour as Flectra numbers them, before its
name, its first line of details under it, and its aside at the row's end. An
option is named by its words alone, and a suggestion by its record's name, as
a screen reader reads them and a test finds them (getByRole('option', { name
})); the second line, the details and the aside describe it
(aria-describedby), read after its name.
A char field's node may type it to a mask — a national ID, an IBAN, a car
plate: "options": { "mask": "9 999 999 999" }, where 9 is a digit (in any
script, kept as 0-9), a a letter, * a letter or a digit, \ before a
character that character itself, and [ ] round the end of it what may be
left out (an IBAN's last groups, as long as its country's); every other
character is the mask's own, written in as the person types — "2 104 " as the
fifth digit is due — and Backspace over one takes the character before it. A
key no slot takes there is refused with why ("a digit goes here, not “x”"),
said while the keys after it go in where they fit — never hidden ("10a2345"
shows "1 023 45"); a paste is laid out against it, one with words round the
value ("ID 1023456789", "IBAN: SA03 …") gives the one value in them, and one
with none, or two, is refused whole, saying why. The field takes the characters typed
("2104556789") once every slot it needs is filled, or as shown
("maskKeeps": "shown": "4821 RKA"); "upper": true writes its letters in
capitals. Left before it is whole, what was typed stays, marked, with how many
are still to type, and the field keeps what it held. A value from outside that
the mask does not fit is shown as it came.
{ "type": "field", "id": "f-iban", "field": "iban", "options": { "mask": "aa99 **** **** **** **** **[** **** **** **]", "upper": true } }A number or an amount whose node says "options": { "shorthand": true } is
typed as agents write big amounts: "3.5m", "500k", "1.2bn", "2 million",
"٣٫٥ مليون", "3,5 Mio.", "1,5 Md" — the number read by the number reader in
the page's way, its last word read as the power of ten it names, worked out on
the digits (1.1m is 1,100,000, never 1,100,000.0000000002). The words are the
page's language's own, as Intl writes compact numbers in it — short and long,
each form it uses — and English's, beside the letters people type anywhere:
k, m, mn, b, bn. While it is typed the box says what it reads ("3.5m is
3,500,000.00"), and once left it shows the whole amount. A letter no such word
begins with is refused, saying so; a paste in shorthand is taken as typed. It
comes in the typed part, with masks.
"widget": "one-time-code" on a char field draws a box for each of a code's
digits (options.length, 4 to 12, 6 unless said; options.letters for
letters too) over one text box with autocomplete="one-time-code", so the
phone's autofill of a code sent by SMS fills it whole, a screen reader reads
one box by its label ("6 digits"), and a code pasted with its spaces or dashes
lands across the boxes at once — a whole message pasted ("Your code is 482
913.") gives the one code of its length in it, else is refused, saying why; a
key refused is said while the keys after it go in. The field takes the code once it is whole — a
step on its change can send it; left before then, it says how many are still to
type. Both come in the typed part (typedPart), the text box meanwhile.
"widget": "tree" on a many2many picks several records of a tree at once —
the areas a buyer wants, a doctor's specialties, a role's permissions — as a
tree of boxes to tick: a branch's box is ticked when all under it are and
part-ticked (aria-checked="mixed") when some are, and ticking it ticks all
under it. Its records are the link's, each placed by its path as the path
picker's are (its names from the top down: see what a link shows), the first
500 the source finds and any a search finds beyond them. What the field keeps
is options.keeps: every record ticked ("all", unless said — a branch's own
record too once all under it are), a whole branch as its own record alone
("top": all of Nasr City kept as Nasr City), or the records with none under
them alone ("leaves"); a record the value holds that the tree does not show
is kept as it is. A search over it (options.search, shown unless false)
keeps the rows whose names have the words, with the branches they are in, open;
how many are chosen is said under it. It is an ARIA tree, several picked: ↓ ↑
move, → opens a branch or goes into it, ← closes it or goes up (the other way
round right to left), Home and End, Space ticks, typing a name's first letters
goes to it. It comes in the path part (pathPart), the tags meanwhile.
{ "type": "field", "id": "f-areas", "field": "areas", "widget": "tree", "options": { "keeps": "top" } }"widget": "slots" on a date and time books a time from those free: a month
whose days are shaded by how they are booked (free times left, fully booked,
closed, a holiday by its name), beside the chosen day's free times as chips,
asked of the data source's slots — a month at a time, again when a field in
options.dependsOn changes or a page of responses sends one (the next booking
is never offered the time the last one took), and once more for the day of a
time picked, so a time someone else booked meanwhile is said and never booked.
The arrows move
across the days, the day's times following, and among the times; Enter books
one. options.endField takes the booking's end. It comes in a part of its own,
fieldia.slots.js (slotsPart), with the date part; without slots in the
data source it is the date and time box.
A line, a paragraph or formatted text kept in several languages (its field's
translate) is a switch over its box, one press for each language named in itself
— English, العربية — the reader's first (the widget's locale), and under it that
language's box: the field's own, its rules as typed, written its own way (Arabic
right to left whatever the page's direction). A language not typed yet is marked on
its press, one a required answer still needs more so, and said to a screen reader;
the arrows move along the switch (mirrored right to left), Home and End to its ends;
a problem takes the focus to its language. Where it is read — a list's cell, a card —
languageWords draws it in the reader's language, else another's with that
language's code beside it ("AR", said as "in Arabic"), and displayValue writes it
in the reader's. It comes in the languages part (languagesPart,
fieldia.languages.js), with @fieldia/core's form code for it; drawn before it
came, its first text is read until it comes. Nothing is translated by a machine.
"widget": "repeat" on a char field says how often something comes back:
every day, every week on the days ticked, every month on a day, its last, or
its first Monday, every so many; never ending, until a day, or a number of
times. Its value is an iCalendar rule (FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,TH;
COUNT=6), said in words under its boxes and at rest — "Every 2 weeks on
Tuesday and Thursday, 6 times" — in a list's column too. options.startField
names the date it starts from. A rule it cannot change is kept as written,
and said so. "widget": "hours" on a json field is a week's opening hours: a
row a weekday, open or closed, its shifts (Add a break splits the last), a
day's hours copied to every day; its value is a booking schedule's hours —
{ "1": [["09:00", "13:00"], ["14:00", "18:00"]] }, by ISO weekday, a day not
named closed — and a shift ending before it starts, or overlapping another,
keeps the record from being saved, said under its day. options.weekStart
(1–7) starts its week; without it, the week's first day where the page is read
(firstWeekday in @fieldia/core), as a repeat's days are offered. Both come in a part of their own, fieldia.schedule.js
(schedulePart), with the date part, whose boxes their days and times are;
(await schedulePart.load()).repeatWords(rule, locale, labels) and
.hoursWords(value, locale, labels) say a value in words for your own code.
What is pasted into a formatted text (html) from Word, Excel, Google Docs or
Google Sheets — or copied from any page — comes in plain, in the field's own
look, in either editor: its headings, bold, italic, underlined and struck
words, links, lists (Word's too, which it writes as paragraphs, nested by
their level) and alignment kept; its fonts, sizes, colours, highlights,
classes, widths and Office's own markup left behind. What is copied or cut
from a Fieldia editor is marked as its own (data-fieldia-copy), so pasted
back there or in another formatted text it keeps what the editor's tools wrote
— a word's colour, highlight and size — and nothing more. Words alone (no HTML)
are the browser's to paste, as before. The cleaner is the text part's: the classic
editor asks for it as something is pasted, and puts the paste in as soon as it
comes. A formatted text keeps tables: their cells, a cell spanning several
(colspan, rowspan), a header row and a cell's alignment (an amount at its
end). Everything is cleaned as every value is: no script, no event, no style
but alignment ever reaches the page. The work item's editor
gets a table tool where a field names table among its tools:
{ "type": "field", "id": "f-fees", "field": "fees", "options": { "tools": ["bold", "italic", "bulletList", "link", "table"] } }Pressed, it puts in a table at a size picked on a grid of 8 by 8 (by the arrow
keys or the pointer, "3 rows by 4 columns"), its header row on and the cursor
in its first cell; with the cursor in a table, it offers Insert row above or
below, Insert column left or right (as the table is drawn: mirrored right to
left), Delete row, Delete column, Header row and Delete table — each one step
the browser's Undo takes back. In a table, Tab goes to the next cell, its words
selected, Shift+Tab back, Tab past the last cell adds a row, and Escape leaves
the table; said once as the cursor first comes into one. In Markdown a table is
GitHub's (| a | b | over | --- | ---: |), both ways; switching asks first
where a table cannot be written so. On paper a table is whole on a sheet where
it fits, else broken between its rows with its header row again — a header row
pasted among its rows, as Word, Excel and Google Docs copy one, or stored so by
an app, is shown and kept in the table's head, so it repeats too.
Rows copied from a spreadsheet and pasted in a cell of a table of lines — a
dropdown's too, where no browser sends a paste: Ctrl or ⌘ and V on it is caught by
a box of the table's own, out of sight — (or on
a cell of @fieldia/grid, chosen or open for typing) go each on its own line from
that cell, across the columns shown, each cell read as its column reads what is
typed (the page's marks and digits in any script, an amount in its line's
currency, a day in the page's order, a choice by its label, a link by its exact
name through the source's search, as its box reads a name typed), lines added for
the rows past the last as the table's max allows. A row whose name reads as no
record — nothing, or more than one, called so — is not pasted at all, never half
laid on a line of another record; what a cell could not take is named with why
under the table. The readers — blockOf, readPastedCell, whyNotPasted, and
pasteRows, which the table and the grid paste a block with — come in the lines
part ((await linesPart.load()).readPastedCell(…)), which the grid and a list's
Import read cells with too.
A signature whose node says options.signs ("form", or the fields by name)
signs those answers: once drawn, typed or uploaded — what is typed in the
answers read first, an answer still to give said instead, the drawing kept on
the pad, the words following the answers until none is left to put right and
Sign now signs that drawing — it keeps who signed
(options.signerField's name, the name typed, else the form's user), when
(the form's clock) and the SHA-256 of the answers with who and when beside its
picture (FileValue.signed). Under it, "Signed by Mona Adel, 19 Oct 2026,
11:42", whether the answers are still as signed — the fingerprint made again
from them — and Change answers, asked in place, which takes it away; the form
locks the answers while it is kept. All of that, and the canonical form
(fieldia-signature/1, @fieldia/core's README) with its functions —
signatureText, signedAnswers, canonicalJson, sha256Hex (the browser's
SubtleCrypto, else worked out the same where a page is served without https),
signAnswers, answersMatch — come in a part of their own,
evidencePart (fieldia.evidence.js), loaded only for a signature that signs
answers: a page with uploads or a plain signature never asks for it. Until it
comes, the files part's pad draws and keeps the picture, and its signing waits
for it — a save waits for that signing: (await evidencePart.load()).answersMatch(…).
A picture field of several photos drawn as "widget": "photos" is a photo
set: its photos as tiles, in the order a person puts them — dragged with the
mouse, a finger resting on one a moment first on a phone (a swipe still
scrolls), or moved with Alt and an arrow key (Home and End to either end, the
arrows mirrored right to left), each move said aloud, Escape putting a drag
back. The first is the cover, marked so and what a list's card and a map's pin
show (options.cover: false marks none: a clinic's before and after); each
other has Make cover. Each photo has Crop and turn: a dialog drawing it
on a canvas, the part kept dragged, sized by a corner or moved by the arrow keys
(Shift and an arrow to size it), kept to options.aspect ("4:3") or a shape
the person picks where it names none, turned a quarter at a time. Applied, the
picture made takes the photo's place — stored at once where the data source
stores files (the form's upload with replaces, its bar on the tile) — and
the photo as it was is kept beside it (FileValue.original, with what was done,
FileValue.edit), so a crop again starts from it and Put back the original
brings it back; options.keepOriginal: false keeps none. options.captions:
true puts a caption's box under each photo (FileValue.caption), read as the
box is left, the photo named by it everywhere — its tools, its dialog's title;
one with no caption is named by its place, "photo 2 of 5", never by its file's
name. Left by Escape, × or a press outside it with a change made, the crop
dialog asks "Discard your changes?" first, in place, as a record's dialog asks;
Cancel lets the change go unasked. Photos are added as a picture field adds them, made smaller first, up to the
field's maxFiles, each on its way a tile with its bar.
{ "type": "field", "id": "f-photos", "field": "photos", "widget": "photos", "options": { "captions": true, "aspect": "4:3", "camera": true } }It comes in photosPart (fieldia.photos.js) with the files part, whose
taking of photos, files on their way and dialog it draws with; a plain picture
field never asks for it. The crop's geometry is there for an app's own:
(await photosPart.load()).drawEdited(document, picture, { turn: 90, crop }).
Not done yet, for 0.29: a photo set inside a table line's cell is untested; pictures a second crop or Put back the original replaced stay in your store (the form never deletes a stored file: they are your store's to clean); a photo stored on another site is cropped only where that store lets the page read it (CORS) — else the dialog says it cannot be read, with nothing to apply. AI help never proposes a photo set's photos, as it never proposes a file.
A line's choice from the app's lists (optionsFrom on a line's selection, its
dependsOn naming a column of the line or parent. and a field of the record)
draws each line's own choices: the cell's form (lineForm) gives the line's
choices and asks its own by its cell's path (form.loadChoices("tools.k1.tool")).
A tool its new connection does not offer — or an option its condition hides as
the line changes (options[].invisible, read on the line and parent.) — is
taken out by the form and said under the cell (state.takenOut, by the cell's
path; the cell's form, lineForm, gives its line's by column, and form.line
the line it is of). lineColumn(form, field, key, column, def) gives a
column as its cell reads at rest — its choices those loaded for that line — for a
grid's cells, a printout, cards. A block pasted reads such a cell among its own
line's choices (PasteTable.choices, form.lineChoices), its links first.
A field whose node says options.scan is scanned into with the camera: a char's
or a text's box, a link's (a many2one), a table's column (cells.<column>.options.scan)
or a table of lines that counts what is scanned. A Scan button at the end of
its box — a line's cell's, its icon alone — opens the camera in a sheet over the
page, the back camera on a phone, with a frame to hold the code in; a code read
fills the field, beeps where the browser lets it and buzzes a phone, and the
sheet closes and stops the camera — as Escape, × and Type it instead do. It
reads QR codes, DataMatrix, EAN-13 and EAN-8, UPC-A and UPC-E, Code 128 and Code
39 (formats keeps it to some), with the browser's own BarcodeDetector where
it reads them all, else with ZXing's readers in the decode part
(fieldia.decode.js, about 40 KB gzipped), loaded only as Scan is pressed in a
browser without — Safari, Firefox, a computer's Chrome. Where the camera is not
allowed, there is none, another app holds it, or the page cannot use one, the
field says why beside the button and the cursor goes to its box, to type. A
code of a kind the field takes nothing from (a shelf's barcode held up for a lot)
is said in the sheet — "This code has no Lot in it" — never met with silence. A
scanner gun (a keyboard wedge) types into the box, and what it typed is read as
the camera reads a code once Enter is pressed or the box is left: a link's record
by its code (by), a GS1 code's part and the fields it fills — a code longer
than the field's most is read whole — while words a person types stay as typed.
A table counted has a box in its sheet to type a code whose label will not scan.
{ "type": "field", "id": "f-patient", "field": "patient_id", "options": { "scan": { "by": "card" } } }
{ "type": "field", "id": "f-lines", "field": "line_ids",
"cells": { "lot": { "options": { "scan": { "formats": ["data_matrix"], "part": "10", "fills": { "expiry": "17", "product_id": { "part": "01", "by": "gtin" } } } } } } }
{ "type": "field", "id": "f-count", "field": "line_ids", "options": { "scan": { "field": "product_id", "count": "counted", "by": "barcode" } } }- Words take the code as read, one line in a char; a GS1 code taken whole is
written as its label prints it,
(01)06285096000842(17)281231(10)25A1234. - A link finds its record by the code through the data source's
search: by the field of its records that holds their codes (by: the search's filter asks for that field equal to the code, its query empty), else by name — the name itself first, then as the source searches names, which may find a product by its barcode. A GTIN of 14 digits is found as the 13 or 12 a shop may keep. One record is taken; none, or several, is said in the sheet, which reads on. - A GS1 code — a medicine's DataMatrix, a GS1-128 barcode — is read by its
parts:
partis the one this field takes, by its Application Identifier (10a lot,21a serial number,01a GTIN,17an expiry), andfillsthe others the same code fills, a line's columns for a cell — a day as the date it names (00the month's last), a measure with its places, a link by its code. A code without the part is said, and the camera reads on. - A table counted (
fieldandcounton a one2many's own node): each code read adds one to the line whosefield— and every column the code fills — holds what it names, else adds a line with one; the sheet stays open, saying each count ("Hand cream 50 ml: 2 counted"), until Done. An item held still is read once; out of sight a moment and back, it is the next. sound: falsekeeps it silent. A Scan is hidden while the field is read-only.
The scan part (scanPart, fieldia.scan.js) draws all of it, loaded with a page
that has a field scanned into; until it comes, the field is its box alone. An
app reads codes its own way — a commercial scanning library, a test's stand-in —
with (await scanPart.load()).useCodeReader({ detect }), detect handed a
video's frame and answering [{ rawValue, format }] as BarcodeDetector does.
An app's bundler makes the decode part a chunk of its own, with @zxing/library
as its index brings it (about 120 KB gzipped, asked for only as Scan is pressed in
a browser that reads no codes itself).
MIT licensed.
