@modular-forms/solid
Advanced tools
Comparing version 0.16.0 to 0.17.0
import { batch, splitProps } from 'solid-js'; | ||
import { getValues, validate } from '../methods'; | ||
import { FormError } from '../exceptions'; | ||
import { getValues, setError, setResponse, validate } from '../methods'; | ||
/** | ||
@@ -9,3 +10,3 @@ * HTML form element that simplifies form submission and disables the browser's | ||
// Split props between local, options and other | ||
const [local, options, other] = splitProps(props, ['of', 'onSubmit'], [ | ||
const [options, other] = splitProps(props, [ | ||
'keepResponse', | ||
@@ -20,5 +21,5 @@ 'shouldActive', | ||
event.preventDefault(); | ||
// Destructure local props | ||
// Destructure props | ||
// eslint-disable-next-line solid/reactivity | ||
const { of: form, onSubmit } = local; | ||
const { of: form, onSubmit, responseDuration: duration } = props; | ||
batch(() => { | ||
@@ -39,8 +40,22 @@ // Reset response if it is not to be kept | ||
} | ||
// If an error occurred, set error response | ||
// If an error occurred, set error to fields and response | ||
} | ||
catch (error) { | ||
form.internal.response.set({ | ||
status: 'error', | ||
message: error?.message || 'An unknown error has occurred.', | ||
batch(() => { | ||
if (error instanceof FormError) { | ||
Object.entries(error.errors).forEach(([name, error]) => { | ||
if (error) { | ||
setError(form, name, error, { | ||
...options, | ||
shouldFocus: false, | ||
}); | ||
} | ||
}); | ||
} | ||
if (!(error instanceof FormError) || error.message) { | ||
setResponse(form, { | ||
status: 'error', | ||
message: error?.message || 'An unknown error has occurred.', | ||
}, { duration }); | ||
} | ||
}); | ||
@@ -47,0 +62,0 @@ // Finally set submitting back to "false" |
export * from './adapters'; | ||
export * from './components'; | ||
export * from './exceptions'; | ||
export * from './methods'; | ||
@@ -4,0 +5,0 @@ export { createForm, createFormStore } from './primitives'; |
import { type JSX } from 'solid-js'; | ||
import type { FieldValues, FormStore, MaybePromise, ResponseData } from '../types'; | ||
import type { FieldValues, FormStore, Maybe, MaybePromise, ResponseData } from '../types'; | ||
/** | ||
@@ -22,7 +22,8 @@ * Value type of the submit event object. | ||
onSubmit: SubmitHandler<TFieldValues>; | ||
keepResponse?: boolean; | ||
shouldActive?: boolean; | ||
shouldTouched?: boolean; | ||
shouldDirty?: boolean; | ||
shouldFocus?: boolean; | ||
responseDuration?: Maybe<number>; | ||
keepResponse?: Maybe<boolean>; | ||
shouldActive?: Maybe<boolean>; | ||
shouldTouched?: Maybe<boolean>; | ||
shouldDirty?: Maybe<boolean>; | ||
shouldFocus?: Maybe<boolean>; | ||
children: JSX.Element; | ||
@@ -29,0 +30,0 @@ }; |
export * from './adapters'; | ||
export * from './components'; | ||
export * from './exceptions'; | ||
export * from './methods'; | ||
@@ -4,0 +5,0 @@ export { createForm, createFormStore } from './primitives'; |
{ | ||
"name": "@modular-forms/solid", | ||
"description": "The modular and type-safe form library for SolidJS", | ||
"version": "0.16.0", | ||
"version": "0.17.0", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "author": "Fabian Hiller", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
771257
186
10668