@formisch/solid 0.3.0 → 0.3.1
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 +2 -1
- package/dist/dev.js +18 -16
- package/dist/dev.jsx +18 -16
- package/dist/index.d.ts +1 -1
- package/dist/index.js +18 -16
- package/dist/index.jsx +18 -16
- package/package.json +14 -14
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Formisch is a schema-based, headless form library for SolidJS. It manages form state and validation. It is type-safe, fast by default and its bundle size is small due to its modular design. Try it out in our [playground](https://stackblitz.com/edit/formisch-playground-solid)!
|
|
4
4
|
|
|
5
|
-
Formisch is also available for [Preact][formisch-preact], [Qwik][formisch-qwik], and [Vue][formisch-vue].
|
|
5
|
+
Formisch is also available for [Preact][formisch-preact], [Qwik][formisch-qwik], [Svelte][formisch-svelte] and [Vue][formisch-vue].
|
|
6
6
|
|
|
7
7
|
## Highlights
|
|
8
8
|
|
|
@@ -77,4 +77,5 @@ This project is available free of charge and licensed under the [MIT license](ht
|
|
|
77
77
|
|
|
78
78
|
[formisch-preact]: https://github.com/fabian-hiller/formisch/tree/main/frameworks/preact
|
|
79
79
|
[formisch-qwik]: https://github.com/fabian-hiller/formisch/tree/main/frameworks/qwik
|
|
80
|
+
[formisch-svelte]: https://github.com/fabian-hiller/formisch/tree/main/frameworks/svelte
|
|
80
81
|
[formisch-vue]: https://github.com/fabian-hiller/formisch/tree/main/frameworks/vue
|
package/dist/dev.js
CHANGED
|
@@ -40,7 +40,7 @@ function initializeFieldStore(internalFieldStore, schema, initialInput, path) {
|
|
|
40
40
|
} else for (let index = 0; index < schema.items; index++) {
|
|
41
41
|
internalFieldStore.children[index] = {};
|
|
42
42
|
path.push(index);
|
|
43
|
-
initializeFieldStore(internalFieldStore.children[index], schema.items[index], initialInput
|
|
43
|
+
initializeFieldStore(internalFieldStore.children[index], schema.items[index], initialInput?.[index], path);
|
|
44
44
|
path.pop();
|
|
45
45
|
}
|
|
46
46
|
const initialItems = internalFieldStore.children.map(createUniqueId);
|
|
@@ -58,7 +58,7 @@ function initializeFieldStore(internalFieldStore, schema, initialInput, path) {
|
|
|
58
58
|
for (const key in schema.entries) {
|
|
59
59
|
internalFieldStore.children[key] = {};
|
|
60
60
|
path.push(key);
|
|
61
|
-
initializeFieldStore(internalFieldStore.children[key], schema.entries[key], initialInput
|
|
61
|
+
initializeFieldStore(internalFieldStore.children[key], schema.entries[key], initialInput?.[key], path);
|
|
62
62
|
path.pop();
|
|
63
63
|
}
|
|
64
64
|
}
|
|
@@ -244,23 +244,24 @@ function setFieldBool(internalFieldStore, type, bool) {
|
|
|
244
244
|
function setFieldInput(internalFieldStore, input) {
|
|
245
245
|
batch(() => {
|
|
246
246
|
if (internalFieldStore.kind === "array") {
|
|
247
|
+
const arrayInput = input ?? [];
|
|
247
248
|
const items = untrack(() => internalFieldStore.items.value);
|
|
248
|
-
if (
|
|
249
|
-
else if (
|
|
250
|
-
if (
|
|
249
|
+
if (arrayInput.length < items.length) internalFieldStore.items.value = items.slice(0, arrayInput.length);
|
|
250
|
+
else if (arrayInput.length > items.length) {
|
|
251
|
+
if (arrayInput.length > internalFieldStore.children.length) {
|
|
251
252
|
const path = JSON.parse(internalFieldStore.name);
|
|
252
|
-
for (let index = internalFieldStore.children.length; index <
|
|
253
|
+
for (let index = internalFieldStore.children.length; index < arrayInput.length; index++) {
|
|
253
254
|
internalFieldStore.children[index] = {};
|
|
254
255
|
path.push(index);
|
|
255
|
-
initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item,
|
|
256
|
+
initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item, arrayInput[index], path);
|
|
256
257
|
path.pop();
|
|
257
258
|
}
|
|
258
259
|
}
|
|
259
|
-
internalFieldStore.items.value = [...items, ...
|
|
260
|
+
internalFieldStore.items.value = [...items, ...arrayInput.slice(items.length).map(createUniqueId)];
|
|
260
261
|
}
|
|
261
|
-
for (let index = 0; index < items.length; index++) setFieldInput(internalFieldStore.children[index],
|
|
262
|
+
for (let index = 0; index < items.length; index++) setFieldInput(internalFieldStore.children[index], arrayInput[index]);
|
|
262
263
|
internalFieldStore.isDirty.value = untrack(() => internalFieldStore.startItems.value).length !== items.length;
|
|
263
|
-
} else if (internalFieldStore.kind === "object") for (const key in internalFieldStore.children) setFieldInput(internalFieldStore.children[key], input[key]);
|
|
264
|
+
} else if (internalFieldStore.kind === "object") for (const key in internalFieldStore.children) setFieldInput(internalFieldStore.children[key], input?.[key]);
|
|
264
265
|
else {
|
|
265
266
|
internalFieldStore.input.value = input;
|
|
266
267
|
internalFieldStore.isTouched.value = true;
|
|
@@ -272,17 +273,18 @@ function setFieldInput(internalFieldStore, input) {
|
|
|
272
273
|
function setInitialFieldInput(internalFieldStore, initialInput) {
|
|
273
274
|
batch(() => {
|
|
274
275
|
if (internalFieldStore.kind === "array") {
|
|
275
|
-
|
|
276
|
+
const initialArrayInput = initialInput ?? [];
|
|
277
|
+
if (initialArrayInput.length > internalFieldStore.children.length) {
|
|
276
278
|
const path = JSON.parse(internalFieldStore.name);
|
|
277
|
-
for (let index = internalFieldStore.children.length; index <
|
|
279
|
+
for (let index = internalFieldStore.children.length; index < initialArrayInput.length; index++) {
|
|
278
280
|
internalFieldStore.children[index] = {};
|
|
279
281
|
path.push(index);
|
|
280
|
-
initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item,
|
|
282
|
+
initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item, initialArrayInput[index], path);
|
|
281
283
|
path.pop();
|
|
282
284
|
}
|
|
283
285
|
}
|
|
284
|
-
internalFieldStore.initialItems.value =
|
|
285
|
-
for (let index = 0; index < internalFieldStore.children.length; index++) setInitialFieldInput(internalFieldStore.children[index],
|
|
286
|
+
internalFieldStore.initialItems.value = initialArrayInput.map(createUniqueId);
|
|
287
|
+
for (let index = 0; index < internalFieldStore.children.length; index++) setInitialFieldInput(internalFieldStore.children[index], initialArrayInput[index]);
|
|
286
288
|
} else if (internalFieldStore.kind === "object") for (const key in internalFieldStore.children) setInitialFieldInput(internalFieldStore.children[key], initialInput?.[key]);
|
|
287
289
|
else internalFieldStore.initialInput.value = initialInput;
|
|
288
290
|
});
|
|
@@ -517,7 +519,7 @@ function validate(form, config) {
|
|
|
517
519
|
function createForm(config) {
|
|
518
520
|
const internalFormStore = createFormStore(
|
|
519
521
|
config,
|
|
520
|
-
|
|
522
|
+
(input) => v.safeParseAsync(config.schema, input)
|
|
521
523
|
);
|
|
522
524
|
const getIsTouched = createMemo(
|
|
523
525
|
() => getFieldBool(internalFormStore, "isTouched")
|
package/dist/dev.jsx
CHANGED
|
@@ -38,7 +38,7 @@ function initializeFieldStore(internalFieldStore, schema, initialInput, path) {
|
|
|
38
38
|
} else for (let index = 0; index < schema.items; index++) {
|
|
39
39
|
internalFieldStore.children[index] = {};
|
|
40
40
|
path.push(index);
|
|
41
|
-
initializeFieldStore(internalFieldStore.children[index], schema.items[index], initialInput
|
|
41
|
+
initializeFieldStore(internalFieldStore.children[index], schema.items[index], initialInput?.[index], path);
|
|
42
42
|
path.pop();
|
|
43
43
|
}
|
|
44
44
|
const initialItems = internalFieldStore.children.map(createId);
|
|
@@ -56,7 +56,7 @@ function initializeFieldStore(internalFieldStore, schema, initialInput, path) {
|
|
|
56
56
|
for (const key in schema.entries) {
|
|
57
57
|
internalFieldStore.children[key] = {};
|
|
58
58
|
path.push(key);
|
|
59
|
-
initializeFieldStore(internalFieldStore.children[key], schema.entries[key], initialInput
|
|
59
|
+
initializeFieldStore(internalFieldStore.children[key], schema.entries[key], initialInput?.[key], path);
|
|
60
60
|
path.pop();
|
|
61
61
|
}
|
|
62
62
|
}
|
|
@@ -242,23 +242,24 @@ function setFieldBool(internalFieldStore, type, bool) {
|
|
|
242
242
|
function setFieldInput(internalFieldStore, input) {
|
|
243
243
|
batch(() => {
|
|
244
244
|
if (internalFieldStore.kind === "array") {
|
|
245
|
+
const arrayInput = input ?? [];
|
|
245
246
|
const items = untrack(() => internalFieldStore.items.value);
|
|
246
|
-
if (
|
|
247
|
-
else if (
|
|
248
|
-
if (
|
|
247
|
+
if (arrayInput.length < items.length) internalFieldStore.items.value = items.slice(0, arrayInput.length);
|
|
248
|
+
else if (arrayInput.length > items.length) {
|
|
249
|
+
if (arrayInput.length > internalFieldStore.children.length) {
|
|
249
250
|
const path = JSON.parse(internalFieldStore.name);
|
|
250
|
-
for (let index = internalFieldStore.children.length; index <
|
|
251
|
+
for (let index = internalFieldStore.children.length; index < arrayInput.length; index++) {
|
|
251
252
|
internalFieldStore.children[index] = {};
|
|
252
253
|
path.push(index);
|
|
253
|
-
initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item,
|
|
254
|
+
initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item, arrayInput[index], path);
|
|
254
255
|
path.pop();
|
|
255
256
|
}
|
|
256
257
|
}
|
|
257
|
-
internalFieldStore.items.value = [...items, ...
|
|
258
|
+
internalFieldStore.items.value = [...items, ...arrayInput.slice(items.length).map(createId)];
|
|
258
259
|
}
|
|
259
|
-
for (let index = 0; index < items.length; index++) setFieldInput(internalFieldStore.children[index],
|
|
260
|
+
for (let index = 0; index < items.length; index++) setFieldInput(internalFieldStore.children[index], arrayInput[index]);
|
|
260
261
|
internalFieldStore.isDirty.value = untrack(() => internalFieldStore.startItems.value).length !== items.length;
|
|
261
|
-
} else if (internalFieldStore.kind === "object") for (const key in internalFieldStore.children) setFieldInput(internalFieldStore.children[key], input[key]);
|
|
262
|
+
} else if (internalFieldStore.kind === "object") for (const key in internalFieldStore.children) setFieldInput(internalFieldStore.children[key], input?.[key]);
|
|
262
263
|
else {
|
|
263
264
|
internalFieldStore.input.value = input;
|
|
264
265
|
internalFieldStore.isTouched.value = true;
|
|
@@ -270,17 +271,18 @@ function setFieldInput(internalFieldStore, input) {
|
|
|
270
271
|
function setInitialFieldInput(internalFieldStore, initialInput) {
|
|
271
272
|
batch(() => {
|
|
272
273
|
if (internalFieldStore.kind === "array") {
|
|
273
|
-
|
|
274
|
+
const initialArrayInput = initialInput ?? [];
|
|
275
|
+
if (initialArrayInput.length > internalFieldStore.children.length) {
|
|
274
276
|
const path = JSON.parse(internalFieldStore.name);
|
|
275
|
-
for (let index = internalFieldStore.children.length; index <
|
|
277
|
+
for (let index = internalFieldStore.children.length; index < initialArrayInput.length; index++) {
|
|
276
278
|
internalFieldStore.children[index] = {};
|
|
277
279
|
path.push(index);
|
|
278
|
-
initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item,
|
|
280
|
+
initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item, initialArrayInput[index], path);
|
|
279
281
|
path.pop();
|
|
280
282
|
}
|
|
281
283
|
}
|
|
282
|
-
internalFieldStore.initialItems.value =
|
|
283
|
-
for (let index = 0; index < internalFieldStore.children.length; index++) setInitialFieldInput(internalFieldStore.children[index],
|
|
284
|
+
internalFieldStore.initialItems.value = initialArrayInput.map(createId);
|
|
285
|
+
for (let index = 0; index < internalFieldStore.children.length; index++) setInitialFieldInput(internalFieldStore.children[index], initialArrayInput[index]);
|
|
284
286
|
} else if (internalFieldStore.kind === "object") for (const key in internalFieldStore.children) setInitialFieldInput(internalFieldStore.children[key], initialInput?.[key]);
|
|
285
287
|
else internalFieldStore.initialInput.value = initialInput;
|
|
286
288
|
});
|
|
@@ -519,7 +521,7 @@ import * as v2 from "valibot";
|
|
|
519
521
|
function createForm(config) {
|
|
520
522
|
const internalFormStore = createFormStore(
|
|
521
523
|
config,
|
|
522
|
-
|
|
524
|
+
(input) => v2.safeParseAsync(config.schema, input)
|
|
523
525
|
);
|
|
524
526
|
const getIsTouched = createMemo(
|
|
525
527
|
() => getFieldBool(internalFormStore, "isTouched")
|
package/dist/index.d.ts
CHANGED
|
@@ -371,7 +371,7 @@ interface FieldArrayProps<TSchema extends Schema = Schema, TFieldArrayPath exten
|
|
|
371
371
|
declare function FieldArray<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(props: FieldArrayProps<TSchema, TFieldArrayPath>): JSX.Element;
|
|
372
372
|
//#endregion
|
|
373
373
|
//#region src/components/Form/Form.d.ts
|
|
374
|
-
type FormProps<TSchema extends Schema = Schema> = Omit<JSX.FormHTMLAttributes<HTMLFormElement>, "onSubmit"> & {
|
|
374
|
+
type FormProps<TSchema extends Schema = Schema> = Omit<JSX.FormHTMLAttributes<HTMLFormElement>, "onSubmit" | "novalidate" | "noValidate"> & {
|
|
375
375
|
of: FormStore<TSchema>;
|
|
376
376
|
children: JSX.Element;
|
|
377
377
|
onSubmit: SubmitHandler<TSchema>;
|
package/dist/index.js
CHANGED
|
@@ -40,7 +40,7 @@ function initializeFieldStore(internalFieldStore, schema, initialInput, path) {
|
|
|
40
40
|
} else for (let index = 0; index < schema.items; index++) {
|
|
41
41
|
internalFieldStore.children[index] = {};
|
|
42
42
|
path.push(index);
|
|
43
|
-
initializeFieldStore(internalFieldStore.children[index], schema.items[index], initialInput
|
|
43
|
+
initializeFieldStore(internalFieldStore.children[index], schema.items[index], initialInput?.[index], path);
|
|
44
44
|
path.pop();
|
|
45
45
|
}
|
|
46
46
|
const initialItems = internalFieldStore.children.map(createUniqueId);
|
|
@@ -58,7 +58,7 @@ function initializeFieldStore(internalFieldStore, schema, initialInput, path) {
|
|
|
58
58
|
for (const key in schema.entries) {
|
|
59
59
|
internalFieldStore.children[key] = {};
|
|
60
60
|
path.push(key);
|
|
61
|
-
initializeFieldStore(internalFieldStore.children[key], schema.entries[key], initialInput
|
|
61
|
+
initializeFieldStore(internalFieldStore.children[key], schema.entries[key], initialInput?.[key], path);
|
|
62
62
|
path.pop();
|
|
63
63
|
}
|
|
64
64
|
}
|
|
@@ -244,23 +244,24 @@ function setFieldBool(internalFieldStore, type, bool) {
|
|
|
244
244
|
function setFieldInput(internalFieldStore, input) {
|
|
245
245
|
batch(() => {
|
|
246
246
|
if (internalFieldStore.kind === "array") {
|
|
247
|
+
const arrayInput = input ?? [];
|
|
247
248
|
const items = untrack(() => internalFieldStore.items.value);
|
|
248
|
-
if (
|
|
249
|
-
else if (
|
|
250
|
-
if (
|
|
249
|
+
if (arrayInput.length < items.length) internalFieldStore.items.value = items.slice(0, arrayInput.length);
|
|
250
|
+
else if (arrayInput.length > items.length) {
|
|
251
|
+
if (arrayInput.length > internalFieldStore.children.length) {
|
|
251
252
|
const path = JSON.parse(internalFieldStore.name);
|
|
252
|
-
for (let index = internalFieldStore.children.length; index <
|
|
253
|
+
for (let index = internalFieldStore.children.length; index < arrayInput.length; index++) {
|
|
253
254
|
internalFieldStore.children[index] = {};
|
|
254
255
|
path.push(index);
|
|
255
|
-
initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item,
|
|
256
|
+
initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item, arrayInput[index], path);
|
|
256
257
|
path.pop();
|
|
257
258
|
}
|
|
258
259
|
}
|
|
259
|
-
internalFieldStore.items.value = [...items, ...
|
|
260
|
+
internalFieldStore.items.value = [...items, ...arrayInput.slice(items.length).map(createUniqueId)];
|
|
260
261
|
}
|
|
261
|
-
for (let index = 0; index < items.length; index++) setFieldInput(internalFieldStore.children[index],
|
|
262
|
+
for (let index = 0; index < items.length; index++) setFieldInput(internalFieldStore.children[index], arrayInput[index]);
|
|
262
263
|
internalFieldStore.isDirty.value = untrack(() => internalFieldStore.startItems.value).length !== items.length;
|
|
263
|
-
} else if (internalFieldStore.kind === "object") for (const key in internalFieldStore.children) setFieldInput(internalFieldStore.children[key], input[key]);
|
|
264
|
+
} else if (internalFieldStore.kind === "object") for (const key in internalFieldStore.children) setFieldInput(internalFieldStore.children[key], input?.[key]);
|
|
264
265
|
else {
|
|
265
266
|
internalFieldStore.input.value = input;
|
|
266
267
|
internalFieldStore.isTouched.value = true;
|
|
@@ -272,17 +273,18 @@ function setFieldInput(internalFieldStore, input) {
|
|
|
272
273
|
function setInitialFieldInput(internalFieldStore, initialInput) {
|
|
273
274
|
batch(() => {
|
|
274
275
|
if (internalFieldStore.kind === "array") {
|
|
275
|
-
|
|
276
|
+
const initialArrayInput = initialInput ?? [];
|
|
277
|
+
if (initialArrayInput.length > internalFieldStore.children.length) {
|
|
276
278
|
const path = JSON.parse(internalFieldStore.name);
|
|
277
|
-
for (let index = internalFieldStore.children.length; index <
|
|
279
|
+
for (let index = internalFieldStore.children.length; index < initialArrayInput.length; index++) {
|
|
278
280
|
internalFieldStore.children[index] = {};
|
|
279
281
|
path.push(index);
|
|
280
|
-
initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item,
|
|
282
|
+
initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item, initialArrayInput[index], path);
|
|
281
283
|
path.pop();
|
|
282
284
|
}
|
|
283
285
|
}
|
|
284
|
-
internalFieldStore.initialItems.value =
|
|
285
|
-
for (let index = 0; index < internalFieldStore.children.length; index++) setInitialFieldInput(internalFieldStore.children[index],
|
|
286
|
+
internalFieldStore.initialItems.value = initialArrayInput.map(createUniqueId);
|
|
287
|
+
for (let index = 0; index < internalFieldStore.children.length; index++) setInitialFieldInput(internalFieldStore.children[index], initialArrayInput[index]);
|
|
286
288
|
} else if (internalFieldStore.kind === "object") for (const key in internalFieldStore.children) setInitialFieldInput(internalFieldStore.children[key], initialInput?.[key]);
|
|
287
289
|
else internalFieldStore.initialInput.value = initialInput;
|
|
288
290
|
});
|
|
@@ -517,7 +519,7 @@ function validate(form, config) {
|
|
|
517
519
|
function createForm(config) {
|
|
518
520
|
const internalFormStore = createFormStore(
|
|
519
521
|
config,
|
|
520
|
-
|
|
522
|
+
(input) => v.safeParseAsync(config.schema, input)
|
|
521
523
|
);
|
|
522
524
|
const getIsTouched = createMemo(
|
|
523
525
|
() => getFieldBool(internalFormStore, "isTouched")
|
package/dist/index.jsx
CHANGED
|
@@ -38,7 +38,7 @@ function initializeFieldStore(internalFieldStore, schema, initialInput, path) {
|
|
|
38
38
|
} else for (let index = 0; index < schema.items; index++) {
|
|
39
39
|
internalFieldStore.children[index] = {};
|
|
40
40
|
path.push(index);
|
|
41
|
-
initializeFieldStore(internalFieldStore.children[index], schema.items[index], initialInput
|
|
41
|
+
initializeFieldStore(internalFieldStore.children[index], schema.items[index], initialInput?.[index], path);
|
|
42
42
|
path.pop();
|
|
43
43
|
}
|
|
44
44
|
const initialItems = internalFieldStore.children.map(createId);
|
|
@@ -56,7 +56,7 @@ function initializeFieldStore(internalFieldStore, schema, initialInput, path) {
|
|
|
56
56
|
for (const key in schema.entries) {
|
|
57
57
|
internalFieldStore.children[key] = {};
|
|
58
58
|
path.push(key);
|
|
59
|
-
initializeFieldStore(internalFieldStore.children[key], schema.entries[key], initialInput
|
|
59
|
+
initializeFieldStore(internalFieldStore.children[key], schema.entries[key], initialInput?.[key], path);
|
|
60
60
|
path.pop();
|
|
61
61
|
}
|
|
62
62
|
}
|
|
@@ -242,23 +242,24 @@ function setFieldBool(internalFieldStore, type, bool) {
|
|
|
242
242
|
function setFieldInput(internalFieldStore, input) {
|
|
243
243
|
batch(() => {
|
|
244
244
|
if (internalFieldStore.kind === "array") {
|
|
245
|
+
const arrayInput = input ?? [];
|
|
245
246
|
const items = untrack(() => internalFieldStore.items.value);
|
|
246
|
-
if (
|
|
247
|
-
else if (
|
|
248
|
-
if (
|
|
247
|
+
if (arrayInput.length < items.length) internalFieldStore.items.value = items.slice(0, arrayInput.length);
|
|
248
|
+
else if (arrayInput.length > items.length) {
|
|
249
|
+
if (arrayInput.length > internalFieldStore.children.length) {
|
|
249
250
|
const path = JSON.parse(internalFieldStore.name);
|
|
250
|
-
for (let index = internalFieldStore.children.length; index <
|
|
251
|
+
for (let index = internalFieldStore.children.length; index < arrayInput.length; index++) {
|
|
251
252
|
internalFieldStore.children[index] = {};
|
|
252
253
|
path.push(index);
|
|
253
|
-
initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item,
|
|
254
|
+
initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item, arrayInput[index], path);
|
|
254
255
|
path.pop();
|
|
255
256
|
}
|
|
256
257
|
}
|
|
257
|
-
internalFieldStore.items.value = [...items, ...
|
|
258
|
+
internalFieldStore.items.value = [...items, ...arrayInput.slice(items.length).map(createId)];
|
|
258
259
|
}
|
|
259
|
-
for (let index = 0; index < items.length; index++) setFieldInput(internalFieldStore.children[index],
|
|
260
|
+
for (let index = 0; index < items.length; index++) setFieldInput(internalFieldStore.children[index], arrayInput[index]);
|
|
260
261
|
internalFieldStore.isDirty.value = untrack(() => internalFieldStore.startItems.value).length !== items.length;
|
|
261
|
-
} else if (internalFieldStore.kind === "object") for (const key in internalFieldStore.children) setFieldInput(internalFieldStore.children[key], input[key]);
|
|
262
|
+
} else if (internalFieldStore.kind === "object") for (const key in internalFieldStore.children) setFieldInput(internalFieldStore.children[key], input?.[key]);
|
|
262
263
|
else {
|
|
263
264
|
internalFieldStore.input.value = input;
|
|
264
265
|
internalFieldStore.isTouched.value = true;
|
|
@@ -270,17 +271,18 @@ function setFieldInput(internalFieldStore, input) {
|
|
|
270
271
|
function setInitialFieldInput(internalFieldStore, initialInput) {
|
|
271
272
|
batch(() => {
|
|
272
273
|
if (internalFieldStore.kind === "array") {
|
|
273
|
-
|
|
274
|
+
const initialArrayInput = initialInput ?? [];
|
|
275
|
+
if (initialArrayInput.length > internalFieldStore.children.length) {
|
|
274
276
|
const path = JSON.parse(internalFieldStore.name);
|
|
275
|
-
for (let index = internalFieldStore.children.length; index <
|
|
277
|
+
for (let index = internalFieldStore.children.length; index < initialArrayInput.length; index++) {
|
|
276
278
|
internalFieldStore.children[index] = {};
|
|
277
279
|
path.push(index);
|
|
278
|
-
initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item,
|
|
280
|
+
initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item, initialArrayInput[index], path);
|
|
279
281
|
path.pop();
|
|
280
282
|
}
|
|
281
283
|
}
|
|
282
|
-
internalFieldStore.initialItems.value =
|
|
283
|
-
for (let index = 0; index < internalFieldStore.children.length; index++) setInitialFieldInput(internalFieldStore.children[index],
|
|
284
|
+
internalFieldStore.initialItems.value = initialArrayInput.map(createId);
|
|
285
|
+
for (let index = 0; index < internalFieldStore.children.length; index++) setInitialFieldInput(internalFieldStore.children[index], initialArrayInput[index]);
|
|
284
286
|
} else if (internalFieldStore.kind === "object") for (const key in internalFieldStore.children) setInitialFieldInput(internalFieldStore.children[key], initialInput?.[key]);
|
|
285
287
|
else internalFieldStore.initialInput.value = initialInput;
|
|
286
288
|
});
|
|
@@ -519,7 +521,7 @@ import * as v2 from "valibot";
|
|
|
519
521
|
function createForm(config) {
|
|
520
522
|
const internalFormStore = createFormStore(
|
|
521
523
|
config,
|
|
522
|
-
|
|
524
|
+
(input) => v2.safeParseAsync(config.schema, input)
|
|
523
525
|
);
|
|
524
526
|
const getIsTouched = createMemo(
|
|
525
527
|
() => getFieldBool(internalFormStore, "isTouched")
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formisch/solid",
|
|
3
3
|
"description": "The modular and type-safe form library for SolidJS",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Fabian Hiller",
|
|
7
7
|
"homepage": "https://formisch.dev",
|
|
@@ -43,18 +43,8 @@
|
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public"
|
|
45
45
|
},
|
|
46
|
-
"scripts": {
|
|
47
|
-
"test": "vitest --typecheck",
|
|
48
|
-
"lint": "eslint \"src/**/*.ts*\" && tsc --noEmit",
|
|
49
|
-
"lint.fix": "eslint \"src/**/*.ts*\" --fix",
|
|
50
|
-
"format": "prettier --write ./src",
|
|
51
|
-
"format.check": "prettier --check ./src",
|
|
52
|
-
"build": "tsup && tsdown"
|
|
53
|
-
},
|
|
54
46
|
"devDependencies": {
|
|
55
47
|
"@eslint/js": "^9.31.0",
|
|
56
|
-
"@formisch/core": "workspace:*",
|
|
57
|
-
"@formisch/methods": "workspace:*",
|
|
58
48
|
"@vitest/coverage-v8": "^3.2.4",
|
|
59
49
|
"eslint": "^9.31.0",
|
|
60
50
|
"eslint-plugin-import": "^2.32.0",
|
|
@@ -71,7 +61,9 @@
|
|
|
71
61
|
"typescript": "^5.8.3",
|
|
72
62
|
"typescript-eslint": "^8.36.0",
|
|
73
63
|
"valibot": "^1.1.0",
|
|
74
|
-
"vitest": "3.2.4"
|
|
64
|
+
"vitest": "3.2.4",
|
|
65
|
+
"@formisch/core": "0.3.1",
|
|
66
|
+
"@formisch/methods": "0.2.0"
|
|
75
67
|
},
|
|
76
68
|
"peerDependencies": {
|
|
77
69
|
"solid-js": "^1.6.0",
|
|
@@ -84,5 +76,13 @@
|
|
|
84
76
|
}
|
|
85
77
|
},
|
|
86
78
|
"browser": {},
|
|
87
|
-
"typesVersions": {}
|
|
88
|
-
|
|
79
|
+
"typesVersions": {},
|
|
80
|
+
"scripts": {
|
|
81
|
+
"test": "vitest --typecheck",
|
|
82
|
+
"lint": "eslint \"src/**/*.ts*\" && tsc --noEmit",
|
|
83
|
+
"lint.fix": "eslint \"src/**/*.ts*\" --fix",
|
|
84
|
+
"format": "prettier --write ./src",
|
|
85
|
+
"format.check": "prettier --check ./src",
|
|
86
|
+
"build": "tsup && tsdown"
|
|
87
|
+
}
|
|
88
|
+
}
|