@dmitryvim/form-builder 0.5.4 → 0.7.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
@@ -322,7 +322,7 @@ If you are stuck on a browser without `ResizeObserver` (very old) and cannot def
322
322
  - **Text**: Single-line with pattern validation, length limits
323
323
  - **Textarea**: Multi-line with configurable rows
324
324
  - **Number**: Numeric input with min/max/step/decimals (no `decimals` → value is kept as typed; set `decimals` to round on extraction)
325
- - **Select**: Dropdown with options and default values
325
+ - **Select**: Dropdown with options and default values. Renders a leading empty option (label: `placeholder` or a localized "Select…"); with no selection the field extracts as `null`, and `required` fails until an option is chosen (v0.6.0)
326
326
  - **Switcher**: Segmented button group (all options visible, ≤4) — same data model as Select
327
327
  - **Colour**: Colour picker with hex values (single or palette)
328
328
  - **Slider**: Range slider with linear/exponential scales (v0.2.7+)
@@ -389,6 +389,12 @@ const form = createFormBuilder({
389
389
  // v0.2.4: Verbose error logging
390
390
  verboseErrors?: boolean, // Default: false (memory leak warnings, validation details)
391
391
 
392
+ // v0.6.0: postMessage opt-in for submitForm()/saveDraft().
393
+ // null (default) = never post. Set the parent frame's origin — or "*" to
394
+ // knowingly broadcast — to receive {type: "formSubmit"|"formDraft", data, schema}
395
+ // messages on window.parent. (Before 0.6.0 the library always broadcast with "*".)
396
+ postMessageTarget?: string | null,
397
+
392
398
  // v0.2.0: CSS theming
393
399
  theme?: {
394
400
  primaryColor?: string,
@@ -402,9 +408,14 @@ const form = createFormBuilder({
402
408
  // Render form
403
409
  form.renderForm(rootElement, schema, prefillData);
404
410
 
405
- // Get form data
411
+ // Get form data — a silent read, safe to poll (v0.7.0: never paints errors)
406
412
  const result = form.getFormData(); // { valid, errors, data }
407
413
 
414
+ // v0.7.0: on the submit click, paint every error next to its field ...
415
+ const checked = form.showErrors(); // same { valid, errors, data }
416
+ // ... and scroll to / focus the first one (does not validate itself)
417
+ if (!checked.valid) form.focusFirstError(); // returns false when nothing is marked
418
+
408
419
  // v0.2.0: Update data without re-rendering
409
420
  form.setFormData({ name: 'John', email: 'john@example.com' });
410
421
  form.updateField('email', 'newemail@example.com');