@reformer/core 1.1.0-beta.2 → 1.1.0-beta.3
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/llms.txt +41 -3
- package/package.json +1 -1
package/llms.txt
CHANGED
|
@@ -345,19 +345,57 @@ form.items.push({ id: '1', name: 'Item' }); // Array operations
|
|
|
345
345
|
|
|
346
346
|
## 9. ARRAY SCHEMA FORMAT
|
|
347
347
|
|
|
348
|
+
**Array items are sub-forms!** Each array element is a complete sub-form with its own fields, validation, and behavior.
|
|
349
|
+
|
|
348
350
|
```typescript
|
|
349
351
|
// ✅ CORRECT - use tuple format for arrays
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
352
|
+
// The template item defines the sub-form schema for each array element
|
|
353
|
+
const itemSchema = {
|
|
354
|
+
id: { value: '', component: Input },
|
|
355
|
+
name: { value: '', component: Input },
|
|
356
|
+
price: { value: 0, component: Input, componentProps: { type: 'number' } },
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
const schema: FormSchema<MyForm> = {
|
|
360
|
+
items: [itemSchema], // Array of sub-forms
|
|
353
361
|
};
|
|
354
362
|
|
|
363
|
+
// Each array item is a GroupNode (sub-form) with its own controls:
|
|
364
|
+
form.items.map((item) => {
|
|
365
|
+
// item is a sub-form (GroupNode) - access fields like nested form
|
|
366
|
+
item.name.setValue('New Name');
|
|
367
|
+
item.price.value.value; // Get current value
|
|
368
|
+
});
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
```typescript
|
|
355
372
|
// ❌ WRONG - object format is NOT supported
|
|
356
373
|
const schema = {
|
|
357
374
|
items: { schema: itemSchema, initialItems: [] }, // This will NOT work
|
|
358
375
|
};
|
|
359
376
|
```
|
|
360
377
|
|
|
378
|
+
### Array Item as Sub-Form
|
|
379
|
+
|
|
380
|
+
```typescript
|
|
381
|
+
// Validation for array items (each item is a sub-form)
|
|
382
|
+
validateItems(path.items, (itemPath) => {
|
|
383
|
+
// itemPath provides paths to sub-form fields
|
|
384
|
+
required(itemPath.name);
|
|
385
|
+
min(itemPath.price, 0);
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
// Render array items - each item is a sub-form
|
|
389
|
+
{form.items.map((item, index) => (
|
|
390
|
+
<div key={item.id}>
|
|
391
|
+
{/* item is a sub-form - use FormField for each field */}
|
|
392
|
+
<FormField control={item.name} />
|
|
393
|
+
<FormField control={item.price} />
|
|
394
|
+
<button onClick={() => form.items.removeAt(index)}>Remove</button>
|
|
395
|
+
</div>
|
|
396
|
+
))}
|
|
397
|
+
```
|
|
398
|
+
|
|
361
399
|
## 10. ASYNC WATCHFIELD (CRITICALLY IMPORTANT)
|
|
362
400
|
|
|
363
401
|
```typescript
|