@dmitryvim/form-builder 0.2.5 → 0.2.7

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
@@ -81,7 +81,6 @@ This package ships with complete TypeScript definitions. Ensure your `tsconfig.j
81
81
 
82
82
  ```json
83
83
  {
84
- "version": "0.3",
85
84
  "title": "Contact Form",
86
85
  "elements": [
87
86
  {
@@ -119,7 +118,6 @@ This package ships with complete TypeScript definitions. Ensure your `tsconfig.j
119
118
 
120
119
  ```json
121
120
  {
122
- "version": "0.3",
123
121
  "title": "Product Registration",
124
122
  "elements": [
125
123
  {
@@ -468,6 +466,127 @@ When a user clicks the download button in readonly mode, the form builder uses t
468
466
 
469
467
  `getThumbnail` must be async (return `Promise`). TypeScript enforces this at compile-time. If you provide a synchronous handler, the error will occur at first file usage (not at form instantiation). This is intentional - we avoid validation calls that would trigger unnecessary API requests. Follow the **FAIL FAST** principle: errors surface naturally at usage.
470
468
 
469
+ ### Conditional Field Visibility
470
+
471
+ Show or hide fields based on form data values using the `displayIf` property:
472
+
473
+ ```typescript
474
+ interface DisplayCondition {
475
+ key: string; // Field key to check (supports nested paths)
476
+ equals?: any; // Value to compare (initial operator)
477
+ // Future: notEquals, in, exists, greaterThan, lessThan, and/or
478
+ }
479
+ ```
480
+
481
+ **Simple Condition:**
482
+ ```json
483
+ {
484
+ "type": "select",
485
+ "key": "background_mode",
486
+ "label": "Background Mode",
487
+ "options": [
488
+ { "value": "use_color", "label": "Solid Color" },
489
+ { "value": "use_image", "label": "Image" }
490
+ ]
491
+ },
492
+ {
493
+ "type": "text",
494
+ "key": "background_image",
495
+ "label": "Background Image URL",
496
+ "displayIf": {
497
+ "key": "background_mode",
498
+ "equals": "use_image"
499
+ }
500
+ }
501
+ ```
502
+
503
+ **Nested Path:**
504
+ ```json
505
+ {
506
+ "type": "text",
507
+ "key": "city_details",
508
+ "label": "City-Specific Information",
509
+ "displayIf": {
510
+ "key": "address.city",
511
+ "equals": "New York"
512
+ }
513
+ }
514
+ ```
515
+
516
+ **Array Indices:**
517
+ ```json
518
+ {
519
+ "type": "text",
520
+ "key": "first_item_note",
521
+ "label": "Note for First Item",
522
+ "displayIf": {
523
+ "key": "items[0].quantity",
524
+ "equals": 1
525
+ }
526
+ }
527
+ ```
528
+
529
+ **Hide Entire Sections:**
530
+ ```json
531
+ {
532
+ "type": "container",
533
+ "key": "advanced_settings",
534
+ "label": "Advanced Settings",
535
+ "displayIf": {
536
+ "key": "mode",
537
+ "equals": "advanced"
538
+ },
539
+ "elements": [
540
+ // All child elements are hidden when container is hidden
541
+ ]
542
+ }
543
+ ```
544
+
545
+ **How It Works:**
546
+
547
+ - Fields with unmet conditions are **not rendered** and **excluded from form data**
548
+ - Conditions are evaluated before rendering each element
549
+ - Automatic re-evaluation when dependency fields change (integrated with onChange system)
550
+ - Works in both edit and readonly modes
551
+ - Safe handling of undefined/null values
552
+
553
+ **Path Resolution:**
554
+
555
+ - **Dot notation**: `user.profile.name`, `settings.theme.primaryColor`
556
+ - **Array indices**: `items[0].name`, `addresses[1].city`
557
+ - **Mixed**: `users[0].profile.email`
558
+
559
+ **Future Extensibility:**
560
+
561
+ The `displayIf` system is designed for future expansion:
562
+
563
+ ```typescript
564
+ // Future operators (planned)
565
+ {
566
+ "displayIf": {
567
+ "key": "age",
568
+ "greaterThan": 18
569
+ }
570
+ }
571
+
572
+ {
573
+ "displayIf": {
574
+ "key": "status",
575
+ "in": ["active", "pending"]
576
+ }
577
+ }
578
+
579
+ // Future complex conditions (planned)
580
+ {
581
+ "displayIf": {
582
+ "and": [
583
+ { "key": "role", "equals": "admin" },
584
+ { "key": "verified", "equals": true }
585
+ ]
586
+ }
587
+ }
588
+ ```
589
+
471
590
  ## Documentation
472
591
 
473
592
  - **API Reference** - See above for core methods and theming