coles-solid-library 0.4.7 → 0.4.8

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.
Files changed (2) hide show
  1. package/USAGE.html +31 -1
  2. package/package.json +1 -1
package/USAGE.html CHANGED
@@ -551,6 +551,36 @@ fg.addToArray('pets', ['name', []] as any, { name: 'Fido' });
551
551
  fg.validate('pets'); // true now
552
552
  fg.removeFromArray('pets', 0);</code></pre>
553
553
  <p><strong>Item Shape:</strong> Adding to a FormArray requires a control definition tuple: <code>['propName', validators[]]</code>. Provide an object value with those props.</p>
554
+ <h3 id="forms-formarray-toplevel">FormArray as Top-Level Form Data</h3>
555
+ <p>The <code>&lt;Form&gt;</code> component accepts either a <code>FormGroup</code> or a <code>FormArray</code> as its <code>data</code> prop. When using a <code>FormArray</code>, <code>onSubmit</code> receives <code>T[]</code> instead of <code>T</code>.</p>
556
+ <pre><code>import { Form, FormArray, Validators, Button } from 'coles-solid-library';
557
+ import { For } from 'solid-js';
558
+
559
+ interface TodoItem { text: string; done: boolean }
560
+
561
+ const todos = new FormArray&lt;TodoItem&gt;(
562
+ [
563
+ [['text', [Validators.Required]], ['done', []]],
564
+ [Validators.custom&lt;TodoItem[]&gt;('minOne', v =&gt; v.length &gt;= 1)]
565
+ ],
566
+ [{ text: 'Buy milk', done: false }]
567
+ );
568
+
569
+ // onSubmit receives TodoItem[] when data is a FormArray
570
+ &lt;Form data={todos} onSubmit={(items) =&gt; console.log('todos:', items)}&gt;
571
+ &lt;For each={todos.get()}&gt;
572
+ {(item, i) =&gt; (
573
+ &lt;div&gt;
574
+ &lt;input value={item.text}
575
+ onInput={e =&gt; todos.setProperty(i(), 'text', e.currentTarget.value)} /&gt;
576
+ &lt;input type="checkbox" checked={item.done}
577
+ onChange={e =&gt; todos.setProperty(i(), 'done', e.currentTarget.checked)} /&gt;
578
+ &lt;/div&gt;
579
+ )}
580
+ &lt;/For&gt;
581
+ &lt;Button type="submit" theme="primary"&gt;Save&lt;/Button&gt;
582
+ &lt;/Form&gt;</code></pre>
583
+ <p><strong>Note:</strong> When using <code>FormArray</code> as the top-level <code>data</code>, <code>FormField</code> field binding and <code>useFormFieldBinding</code> are not available. Manage array items directly through the FormArray API.</p>
554
584
  <h3 id="forms-async">Async Validators</h3>
555
585
  <p>Create via <code>Validators.asyncCustom('key', asyncFn, hide?)</code>. <code>validate()</code> is optimistic for async; call <code>await validateAsync()</code> to finalize.</p>
556
586
  <h3 id="forms-validation-flow">Validation Flow</h3>
@@ -570,7 +600,7 @@ if (asyncOk) doSubmit();</code></pre>
570
600
  <tr><td>FormGroup&lt;T&gt;</td><td><code>get/getR/set/reset/validate/validateAsync/addValidator/removeValidator/addToArray/removeFromArray/getErrors/hasError/hasValidator/getMeta/getArrayItem/markTouched/markDirty/setError</code></td><td>Root form state + validation engine.</td></tr>
571
601
  <tr><td>FormArray&lt;T&gt;</td><td><code>get/getAt/getProperty/set/setAt/setProperty/add/remove/replace/validate/validateCurrent/hasError/hasValidator/getErrors/getErrorsAt</code></td><td>Dynamic object array with array + control validators.</td></tr>
572
602
  <tr><td>Validators</td><td><code>Required/Email/minLength/maxLength/pattern/custom/asyncCustom</code></td><td>Validator factories; <code>hide</code> predicate suppresses an error.</td></tr>
573
- <tr><td>&lt;Form&gt;</td><td><code>data</code>, <code>onSubmit</code></td><td>Context provider + submit orchestration (sync validate).</td></tr>
603
+ <tr><td>&lt;Form&gt;</td><td><code>data: FormGroup&lt;T&gt; | FormArray&lt;T&gt;</code>, <code>onSubmit</code></td><td>Context provider + submit orchestration. Accepts FormGroup (onSubmit receives T) or FormArray (onSubmit receives T[]).</td></tr>
574
604
  <tr><td>&lt;FormField&gt;</td><td><code>name</code>, <code>formName</code>, <code>required?</code>, others</td><td>Floating legend, focus, error projection region.</td></tr>
575
605
  <tr><td>&lt;ColeError&gt;</td><td><code>errorName</code></td><td>Registers error display element for key.</td></tr>
576
606
  <tr><td>useFormFieldBinding</td><td><code>(key)</code> =&gt; binding object</td><td>Manual binding to a control.</td></tr>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coles-solid-library",
3
- "version": "0.4.7",
3
+ "version": "0.4.8",
4
4
  "description": "A SolidJS mostly UI library",
5
5
  "module": "dist/index.esm.js",
6
6
  "types": "dist/index.d.ts",