blip-cards 3.60.0 → 3.61.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -267,7 +267,7 @@ A structured form (several fields answered in a single interaction, optionally s
267
267
  | `checkbox` | checkbox group (`options`) | array of option `value`s (`[]` when none) |
268
268
  | `file` | file picker (`accept`, `maxSizeMb`, default 20) — requires `on-upload-file`. With `multiple: true`, a list of files (`maxFiles`, default 10) | uploaded media URI; with `multiple: true`, array of uploaded media URIs in the order the files were picked (`[]` when none) |
269
269
 
270
- **Field properties**: `id` and `label` (required; ids must be unique across all steps), `required`, `placeholder`, `helpText`, `minLength`/`maxLength` (text, email, tel, textarea), `min`/`max` (number, date), `pattern` (JS regex source that must match the whole value; invalid expressions are ignored), `mask` (text and tel), `errorMessage` (replaces any validation message of the field, except the "wait for the upload" and "too many files" notices, which can only be changed with `messages.uploading` and `messages.maxFiles`), `options` (`[{ "value", "label" }]`), `accept` and `maxSizeMb` (file, checked for each file), `multiple` (file: the boolean `true` accepts several files in the same field; any other value, including the string `"true"`, is ignored. Turning it on or off on an existing id resets the field, like a type change) and `maxFiles` (file with `multiple`: maximum number of files, rounded down; missing, invalid or below 1 means 10), `value` (pre-fill, see below).
270
+ **Field properties**: `id` and `label` (required; ids must be unique across all steps), `required`, `placeholder`, `helpText`, `minLength`/`maxLength` (text, email, tel, textarea), `min`/`max` (number, date), `pattern` (JS regex source that must match the whole value; invalid expressions are ignored), `mask` (text and tel), `errorMessage` (replaces any validation message of the field, except the "wait for the upload" and "too many files" notices, which can only be changed with `messages.uploading` and `messages.maxFiles`), `options` (`[{ "value", "label" }]`), `accept` and `maxSizeMb` (file, checked for each file), `multiple` (file: the boolean `true` accepts several files in the same field; any other value, including the string `"true"`, is ignored. Turning it on or off on an existing id resets the field, like a type change) and `maxFiles` (file with `multiple`: maximum number of files, rounded down; missing, invalid or below 1 means 10), `value` (pre-fill, see below), `showWhen` (conditional field, see below).
271
271
 
272
272
  - **Pre-fill** (`value`): fills a field with data the bot already knows, usually a Builder variable such as `{{contact.extras.cpf}}`. Pre-filled values are editable, validated like typed values and sent in the content and summary.
273
273
  - `text`, `number`, `email`, `tel`, `date`, `textarea`: a string, trimmed (numbers are converted to strings). With a `mask`, the value is formatted with it (`"12345678909"` → `123.456.789-09`). `number` values must follow the HTML number format (`42`, `-1.5`, `2.5e1`; not `+5`, `0x10` or `1.`) and `date` values must be a valid `YYYY-MM-DD`; anything else is ignored.
@@ -287,6 +287,18 @@ A structured form (several fields answered in a single interaction, optionally s
287
287
  - **Masks**: `0` is a digit, `A` a letter, `*` a letter or digit; any other character is a literal inserted automatically, e.g. `000.000.000-00`, `(00) 00000-0000`, `00000-000`. The value is formatted while typing and is sent as displayed. A masked field is valid only when completely filled.
288
288
  - **Validation** happens in real time: errors are shown under a field after it is left (or after the user tries to continue) and update while typing. The form cannot be advanced/sent while there are errors in the current step; focus goes to the first invalid field.
289
289
  - **Steps**: with more than one step, a "Etapa n de N" header with a progress bar is shown; `Voltar` keeps the values and only the current step is validated before moving on. Single-step forms have no header nor back button.
290
+ - **Conditional fields** (`showWhen`): `{ "field": "<id of another field, any step>", "in": [values] }` or `{ "field": "…", "equals": value }` (string, number or boolean) shows the field only while that field holds one of the values (`in` is used when it has string, number or boolean values, others being ignored, otherwise `equals`; values are compared as strings; a `checkbox` source matches when any selected option is one of them). The field appears and disappears as the answer changes, keeping its position.
291
+ - A hidden field is not validated (`required` and every other rule apply only while it is shown, and a pending or failed upload does not block), is sent empty (`""`, `[]` for `checkbox` and `file` with `multiple`) whatever was typed, and is left out of the summary text and of the read-only summary. What was typed is kept while the card is open and comes back if the field is shown again; it shows no error until it is left or the user tries to continue.
292
+ - A field whose source is hidden is hidden too (chains collapse). Invalid conditions are ignored and the field is always shown: not an object, unknown source (including ignored fields), the field itself, a `file` source, no values, or a cycle (A → B → A).
293
+ - With `steps`, a step whose fields are all hidden is skipped by `Continuar`/`Voltar` and not counted in "Etapa n de N"; the last visible step shows the submit button. The "Etapa n de N" header, its count and the back button follow the visible steps, so they may change as the user answers (a step that appears before the current one does not move the user).
294
+ - In Builder, a hidden field reads as empty (`{{formulario@nome_conjuge}}` → empty).
295
+
296
+ ```json
297
+ { "id": "estado_civil", "label": "Estado civil", "type": "select", "required": true, "options": [{ "value": "solteiro", "label": "Solteiro(a)" }, { "value": "casado", "label": "Casado(a)" }, { "value": "uniao_estavel", "label": "União estável" }] },
298
+ { "id": "nome_conjuge", "label": "Nome do cônjuge", "type": "text", "required": true, "showWhen": { "field": "estado_civil", "in": ["casado", "uniao_estavel"] } },
299
+ { "id": "orgao_expedidor", "label": "Órgão expedidor", "type": "select", "options": [{ "value": "ssp", "label": "SSP" }, { "value": "outro", "label": "Outro" }] },
300
+ { "id": "outro_orgao", "label": "Outro órgão expedidor", "type": "text", "required": true, "showWhen": { "field": "orgao_expedidor", "equals": "outro" } }
301
+ ```
290
302
  - Fields without an `id`, `select`/`radio`/`checkbox` fields without `options` and `file` fields when the host does not provide `on-upload-file` are ignored. Labels are rendered as plain text.
291
303
  - **Upload**: hosts enable `file` fields by passing `on-upload-file` to `blip-card`/`blip-group-card`: `(file: File) => Promise<string | { uri: string }>`. The file type (`accept`, MIME type or extension, wildcards such as `image/*`) and size are checked before calling it; the form cannot be sent while an upload is pending, and a rejected promise shows an error so the user can choose another file.
292
304
  - With `multiple: true`, several files can be picked at once or added one by one (`Escolher arquivos` / `Adicionar arquivo`, with a "n de N arquivos" counter). Each file is checked and uploaded on its own, at most 3 at a time per form (the others are shown as `Enviando…` and start when an upload finishes), is listed with its status (with the reason when it failed) and a `Remover` button, and the picker is disabled once `maxFiles` is reached. Files picked beyond the limit are left out with the `maxFiles` notice, which does not block sending. A file that failed (type, size or upload) blocks sending until it is removed; if the card receives a lower `maxFiles` after the files were picked, the extra files block sending (with the `maxFiles` message) until they are removed; `required` means at least one uploaded file.