Skip to content

Commit 801009f

Browse files
committed
Added ref test
1 parent 1e074b2 commit 801009f

File tree

11 files changed

+55
-8
lines changed

11 files changed

+55
-8
lines changed

packages/react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@
7070
"laravel-precognition": "^0.7.3",
7171
"lodash-es": "^4.17.21"
7272
}
73-
}
73+
}

packages/react/test-app/Pages/FormComponent/Ref.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ export default function Ref() {
2929
formRef.current?.defaults()
3030
}
3131

32+
const callPrecognitionMethods = () => {
33+
const validator = formRef.current?.validator()
34+
35+
if (validator && !formRef.current?.touched('company') && !formRef.current?.valid('company')) {
36+
formRef.current?.validate({ only: ['company'] })
37+
}
38+
}
39+
3240
return (
3341
<div>
3442
<h1>Form Ref Test</h1>
@@ -63,6 +71,7 @@ export default function Ref() {
6371
<button onClick={clearAllErrors}>Clear Errors</button>
6472
<button onClick={setTestError}>Set Test Error</button>
6573
<button onClick={setCurrentAsDefaults}>Set Current as Defaults</button>
74+
<button onClick={callPrecognitionMethods}>Call Precognition Methods</button>
6675
</div>
6776
</div>
6877
)

packages/react/test-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@
2828
"react": "^19.2.0",
2929
"react-dom": "^19.2.0"
3030
}
31-
}
31+
}

packages/svelte/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,4 @@
6666
"laravel-precognition": "^0.7.3",
6767
"lodash-es": "^4.17.21"
6868
}
69-
}
69+
}

packages/svelte/test-app/Pages/FormComponent/Ref.svelte

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828
function setCurrentAsDefaults() {
2929
formRef?.defaults()
3030
}
31+
32+
function callPrecognitionMethods() {
33+
const validator = formRef?.validator()
34+
35+
if (validator && !formRef?.touched('company') && !formRef?.valid('company')) {
36+
formRef?.validate({ only: ['company'] })
37+
}
38+
}
3139
</script>
3240

3341
<div>
@@ -63,5 +71,6 @@
6371
<button on:click={clearAllErrors}> Clear Errors </button>
6472
<button on:click={setTestError}> Set Test Error </button>
6573
<button on:click={setCurrentAsDefaults}> Set Current as Defaults </button>
74+
<button on:click={callPrecognitionMethods}> Call Precognition Methods </button>
6675
</div>
6776
</div>

packages/svelte/test-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@
2525
"@inertiajs/core": "workspace:*",
2626
"@inertiajs/svelte": "workspace:*"
2727
}
28-
}
28+
}

packages/vue3/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,4 @@
6868
"laravel-precognition": "^0.7.3",
6969
"lodash-es": "^4.17.21"
7070
}
71-
}
71+
}

packages/vue3/src/form.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,12 @@ const Form = defineComponent({
255255
form.reset(...fields)
256256
}
257257

258-
const resetAndClearErrors = (...fields: string[]) => {
258+
const clearErrors = (...fields: string[]) => {
259259
form.clearErrors(...fields)
260+
}
261+
262+
const resetAndClearErrors = (...fields: string[]) => {
263+
clearErrors(...fields)
260264
reset(...fields)
261265
}
262266

@@ -287,7 +291,7 @@ const Form = defineComponent({
287291
get validating() {
288292
return form.validating
289293
},
290-
clearErrors: form.clearErrors,
294+
clearErrors,
291295
resetAndClearErrors,
292296
setError: (fieldOrFields: string | Record<string, string>, maybeValue?: string) =>
293297
form.setError((typeof fieldOrFields === 'string' ? { [fieldOrFields]: maybeValue } : fieldOrFields) as Errors),

packages/vue3/test-app/Pages/FormComponent/Ref.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ const setTestError = () => {
2828
const setCurrentAsDefaults = () => {
2929
formRef.value?.defaults()
3030
}
31+
32+
const callPrecognitionMethods = () => {
33+
const validator = formRef.value?.validator()
34+
35+
if (validator && !formRef.value?.touched('company') && !formRef.value?.valid('company')) {
36+
formRef.value?.validate({ only: ['company'] })
37+
}
38+
}
3139
</script>
3240

3341
<template>
@@ -60,6 +68,7 @@ const setCurrentAsDefaults = () => {
6068
<button @click="clearAllErrors">Clear Errors</button>
6169
<button @click="setTestError">Set Test Error</button>
6270
<button @click="setCurrentAsDefaults">Set Current as Defaults</button>
71+
<button @click="callPrecognitionMethods">Call Precognition Methods</button>
6372
</div>
6473
</div>
6574
</template>

packages/vue3/test-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@
2525
"@inertiajs/core": "workspace:*",
2626
"@inertiajs/vue3": "workspace:*"
2727
}
28-
}
28+
}

0 commit comments

Comments
 (0)