dynamic-modal 1.1.24 → 1.1.25
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
|
@@ -441,6 +441,34 @@ dynamically.
|
|
|
441
441
|
}
|
|
442
442
|
```
|
|
443
443
|
|
|
444
|
+
### `watcher`
|
|
445
|
+
|
|
446
|
+
Use `watcher` when you want to display a derived read-only value built from
|
|
447
|
+
other fields in the same modal.
|
|
448
|
+
|
|
449
|
+
`watcher` listens to the fields listed in `watchList`, joins their current
|
|
450
|
+
values, and renders the result using your custom `Input` component in disabled
|
|
451
|
+
mode.
|
|
452
|
+
|
|
453
|
+
Example:
|
|
454
|
+
|
|
455
|
+
```ts
|
|
456
|
+
{
|
|
457
|
+
elementType: 'watcher',
|
|
458
|
+
label: 'Full name preview',
|
|
459
|
+
watchList: ['firstName', 'middleName', 'lastName'],
|
|
460
|
+
style: {
|
|
461
|
+
width: '100%',
|
|
462
|
+
},
|
|
463
|
+
}
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
Typical use cases:
|
|
467
|
+
|
|
468
|
+
- preview a full name from multiple inputs
|
|
469
|
+
- build a quick summary field for the user
|
|
470
|
+
- show a composed display value without storing it as a real form field
|
|
471
|
+
|
|
444
472
|
## Advanced conditions with async actions
|
|
445
473
|
|
|
446
474
|
`renderIf` and `enableIf` can also use async logic instead of static value maps.
|
|
@@ -582,6 +610,40 @@ reservedData: {
|
|
|
582
610
|
|
|
583
611
|
That data will be merged into the object returned by `out`.
|
|
584
612
|
|
|
613
|
+
### 6. Compose a read-only value with `watcher`
|
|
614
|
+
|
|
615
|
+
Use `watcher` when you want the modal to display a value derived from multiple
|
|
616
|
+
fields while the user types.
|
|
617
|
+
|
|
618
|
+
```ts
|
|
619
|
+
fields: [
|
|
620
|
+
{
|
|
621
|
+
elementType: 'input',
|
|
622
|
+
label: 'First name',
|
|
623
|
+
name: 'firstName',
|
|
624
|
+
validation: { required: true, message: 'Required' },
|
|
625
|
+
},
|
|
626
|
+
{
|
|
627
|
+
elementType: 'input',
|
|
628
|
+
label: 'Last name',
|
|
629
|
+
name: 'lastName',
|
|
630
|
+
validation: { required: true, message: 'Required' },
|
|
631
|
+
},
|
|
632
|
+
{
|
|
633
|
+
elementType: 'watcher',
|
|
634
|
+
label: 'Preview',
|
|
635
|
+
watchList: ['firstName', 'lastName'],
|
|
636
|
+
style: { width: '100%' },
|
|
637
|
+
},
|
|
638
|
+
];
|
|
639
|
+
```
|
|
640
|
+
|
|
641
|
+
Important notes:
|
|
642
|
+
|
|
643
|
+
- `watcher` is display-only
|
|
644
|
+
- it does not submit its own value in the modal result
|
|
645
|
+
- it is useful for previews, concatenations, and human-readable summaries
|
|
646
|
+
|
|
585
647
|
## Configuration reference
|
|
586
648
|
|
|
587
649
|
### Modal-level config
|
|
@@ -616,6 +678,12 @@ Most form fields share:
|
|
|
616
678
|
- `renderIf`
|
|
617
679
|
- `enableIf`
|
|
618
680
|
|
|
681
|
+
`watcher` uses:
|
|
682
|
+
|
|
683
|
+
- `label`
|
|
684
|
+
- `style`
|
|
685
|
+
- `watchList`
|
|
686
|
+
|
|
619
687
|
Validation supports:
|
|
620
688
|
|
|
621
689
|
- `required`
|
|
@@ -48,14 +48,17 @@ const MakeSelect = ({ element, control, watch, setValue, unregister, }) => {
|
|
|
48
48
|
}
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
const shouldResolveLiveData = Boolean(elementLiveData?.condition?.includes(name));
|
|
52
|
+
if (shouldResolveLiveData) {
|
|
52
53
|
setLiveSearching(true);
|
|
53
54
|
checkLiveData(formData, { name, type })
|
|
54
55
|
.then((options) => {
|
|
55
56
|
if (options === undefined || options === null)
|
|
56
57
|
return;
|
|
57
58
|
setLiveData(options);
|
|
58
|
-
setValue(elementName,
|
|
59
|
+
setValue(elementName, inputProps.isMulti
|
|
60
|
+
? inputProps.defaultValue ?? []
|
|
61
|
+
: inputProps.defaultValue ?? '');
|
|
59
62
|
})
|
|
60
63
|
.finally(() => {
|
|
61
64
|
setLiveSearching(false);
|
|
@@ -38,7 +38,9 @@ const MakeSelect = ({ element, control, watch, setValue, unregister, }) => {
|
|
|
38
38
|
setLiveSearching,
|
|
39
39
|
unregister,
|
|
40
40
|
setValue,
|
|
41
|
-
liveDataResetValue: inputProps.
|
|
41
|
+
liveDataResetValue: inputProps.isMulti
|
|
42
|
+
? (inputProps.defaultValue ?? [])
|
|
43
|
+
: (inputProps.defaultValue ?? ''),
|
|
42
44
|
});
|
|
43
45
|
if (!render)
|
|
44
46
|
return null;
|
|
@@ -21,7 +21,8 @@ const useConditionalField = ({ watch, elementName, renderIf, enableIf, liveDataC
|
|
|
21
21
|
setRender(renderStatus);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
const shouldResolveLiveData = Boolean(liveDataConfig?.condition?.includes(meta.name));
|
|
25
|
+
if (shouldResolveLiveData && setLiveData) {
|
|
25
26
|
const requestId = ++liveRequestId.current;
|
|
26
27
|
setLiveSearching?.(true);
|
|
27
28
|
try {
|
package/package.json
CHANGED