laravel-precognition-react-inertia
Advanced tools
Comparing version 0.3.2 to 0.4.0
import { RequestMethod, ValidationConfig } from 'laravel-precognition'; | ||
export declare const useForm: <Data extends Record<string, unknown>>(method: RequestMethod, url: string, inputs: Data, config?: ValidationConfig) => any; | ||
import { client } from 'laravel-precognition-react'; | ||
export { client }; | ||
export declare const useForm: <Data extends Record<string, unknown>>(method: RequestMethod | (() => RequestMethod), url: string | (() => string), inputs: Data, config?: ValidationConfig) => any; |
@@ -1,8 +0,7 @@ | ||
import { toSimpleValidationErrors } from 'laravel-precognition'; | ||
import { useForm as usePrecognitiveForm } from 'laravel-precognition-react'; | ||
import { toSimpleValidationErrors, resolveUrl, resolveMethod } from 'laravel-precognition'; | ||
import { useForm as usePrecognitiveForm, client } from 'laravel-precognition-react'; | ||
import { useForm as useInertiaForm } from '@inertiajs/react'; | ||
import { useRef } from 'react'; | ||
export { client }; | ||
export const useForm = (method, url, inputs, config = {}) => { | ||
// @ts-expect-error | ||
method = method.toLowerCase(); | ||
const booted = useRef(false); | ||
@@ -52,5 +51,9 @@ /** | ||
*/ | ||
return Object.assign(inertiaForm, { | ||
const form = Object.assign(inertiaForm, { | ||
validating: precognitiveForm.validating, | ||
touched: precognitiveForm.touched, | ||
touch(name) { | ||
precognitiveForm.touch(name); | ||
return form; | ||
}, | ||
valid: precognitiveForm.valid, | ||
@@ -61,3 +64,3 @@ invalid: precognitiveForm.invalid, | ||
precognitiveForm.setData(key, value); | ||
return this; | ||
return form; | ||
}, | ||
@@ -72,3 +75,3 @@ clearErrors(...names) { | ||
} | ||
return this; | ||
return form; | ||
}, | ||
@@ -82,6 +85,6 @@ reset(...names) { | ||
precognitiveForm.setErrors(errors); | ||
return this; | ||
return form; | ||
}, | ||
setError(key, value) { | ||
this.setErrors({ | ||
form.setErrors({ | ||
...inertiaForm.errors, | ||
@@ -92,7 +95,7 @@ ...typeof value === 'undefined' | ||
}); | ||
return this; | ||
return form; | ||
}, | ||
forgetError(name) { | ||
precognitiveForm.forgetError(name); | ||
return this; | ||
return form; | ||
}, | ||
@@ -102,32 +105,36 @@ validate(name) { | ||
precognitiveForm.validate(name); | ||
return this; | ||
return form; | ||
}, | ||
setValidationTimeout(duration) { | ||
precognitiveForm.setValidationTimeout(duration); | ||
return this; | ||
return form; | ||
}, | ||
validateFiles() { | ||
precognitiveForm.validateFiles(); | ||
return this; | ||
return form; | ||
}, | ||
submit(submitMethod = {}, submitUrl, submitOptions) { | ||
const isPatchedCall = typeof submitMethod !== 'string'; | ||
const userOptions = isPatchedCall | ||
submitOptions = isPatchedCall | ||
? submitMethod | ||
: submitOptions; | ||
const options = { | ||
...userOptions, | ||
submitUrl = isPatchedCall | ||
? resolveUrl(url) | ||
: submitUrl; | ||
submitMethod = isPatchedCall | ||
? resolveMethod(method) | ||
: submitMethod; | ||
inertiaSubmit(submitMethod, submitUrl, { | ||
...submitOptions, | ||
onError: (errors) => { | ||
precognitiveForm.validator().setErrors(errors); | ||
if (userOptions.onError) { | ||
return userOptions.onError(errors); | ||
if (submitOptions.onError) { | ||
return submitOptions.onError(errors); | ||
} | ||
}, | ||
}; | ||
inertiaSubmit(isPatchedCall ? method : submitMethod, | ||
// @ts-expect-error | ||
(isPatchedCall ? url : submitUrl), options); | ||
}); | ||
}, | ||
validator: precognitiveForm.validator, | ||
}); | ||
return form; | ||
}; |
{ | ||
"name": "laravel-precognition-react-inertia", | ||
"version": "0.3.2", | ||
"version": "0.4.0", | ||
"description": "Laravel Precognition (React w/ Inertia).", | ||
@@ -36,4 +36,4 @@ "keywords": [ | ||
"dependencies": { | ||
"laravel-precognition": "0.3.2", | ||
"laravel-precognition-react": "0.3.2" | ||
"laravel-precognition": "0.4.0", | ||
"laravel-precognition-react": "0.4.0" | ||
}, | ||
@@ -40,0 +40,0 @@ "devDependencies": { |
8735
138
+ Addedlaravel-precognition@0.4.0(transitive)
+ Addedlaravel-precognition-react@0.4.0(transitive)
- Removedlaravel-precognition@0.3.2(transitive)
- Removedlaravel-precognition-react@0.3.2(transitive)
Updatedlaravel-precognition@0.4.0