Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions packages/react/src/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ export default function useForm<TForm extends FormDataType<TForm>>(
},
onSuccess: (page) => {
if (isMounted.current) {
setProcessing(false)
setProgress(null)
setErrors({} as FormDataErrors<TForm>)
setHasErrors(false)
setWasSuccessful(true)
Expand All @@ -152,8 +150,6 @@ export default function useForm<TForm extends FormDataType<TForm>>(
},
onError: (errors) => {
if (isMounted.current) {
setProcessing(false)
setProgress(null)
setErrors(errors)
setHasErrors(true)
}
Expand All @@ -163,11 +159,6 @@ export default function useForm<TForm extends FormDataType<TForm>>(
}
},
onCancel: () => {
if (isMounted.current) {
setProcessing(false)
setProgress(null)
}

if (options.onCancel) {
return options.onCancel()
}
Expand Down
7 changes: 0 additions & 7 deletions packages/svelte/src/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@ export default function useForm<TForm extends FormDataType<TForm>>(
}
},
onSuccess: async (page: Page) => {
this.setStore('processing', false)
this.setStore('progress', null)
this.clearErrors()
this.setStore('wasSuccessful', true)
this.setStore('recentlySuccessful', true)
Expand All @@ -206,18 +204,13 @@ export default function useForm<TForm extends FormDataType<TForm>>(
return onSuccess
},
onError: (errors: Errors) => {
this.setStore('processing', false)
this.setStore('progress', null)
this.clearErrors().setError(errors)

if (options.onError) {
return options.onError(errors)
}
},
onCancel: () => {
this.setStore('processing', false)
this.setStore('progress', null)

if (options.onCancel) {
return options.onCancel()
}
Expand Down
7 changes: 0 additions & 7 deletions packages/vue3/src/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,6 @@ export default function useForm<TForm extends FormDataType<TForm>>(
}
},
onSuccess: async (page) => {
this.processing = false
this.progress = null
this.clearErrors()
this.wasSuccessful = true
this.recentlySuccessful = true
Expand All @@ -195,18 +193,13 @@ export default function useForm<TForm extends FormDataType<TForm>>(
return onSuccess
},
onError: (errors) => {
this.processing = false
this.progress = null
this.clearErrors().setError(errors)

if (options.onError) {
return options.onError(errors)
}
},
onCancel: () => {
this.processing = false
this.progress = null

if (options.onCancel) {
return options.onCancel()
}
Expand Down
96 changes: 30 additions & 66 deletions tests/form-helper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -658,36 +658,6 @@ test.describe('Form Helper', () => {
await expect(pageData).toHaveProperty('version')
})

test('marks the form as no longer processing', async ({ page }) => {
await page.getByRole('button', { exact: true, name: 'onSuccess resets processing' }).click()

const data = await page.evaluate(() => (window as any).data)

const processing = data.find((d) => d.event === 'onStart' && d.type === 'processing').data
const notProcessing = data.find((d) => d.event === 'onFinish' && d.type === 'processing').data

await expect(processing).toBe(true)
await expect(notProcessing).toBe(false)
})

test('resets the progress property back to null', async ({ page }) => {
await clickAndWaitForResponse(page, 'onSuccess progress property', 'sleep', 'button')

const messages = await page.evaluate(() => (window as any).events)
const data = await page.evaluate(() => (window as any).data)
const event = data.find((d) => d.event === 'onProgress' && d.type === 'progress').data
const endEvent = data.find((d) => d.event === 'onFinish' && d.type === 'progress').data

await expect(event).toHaveProperty('percentage')
await expect(event).toHaveProperty('total')
await expect(event).toHaveProperty('loaded')
await expect(event.percentage).toBeGreaterThanOrEqual(0)
await expect(event.percentage).toBeLessThanOrEqual(100)

await expect(messages[4]).toBe('onFinish')
await expect(endEvent).toBeNull()
})

test('can delay onFinish from firing by returning a promise', async ({ page }) => {
await clickAndWaitForResponse(page, 'onSuccess promise', '/dump/post', 'button')

Expand Down Expand Up @@ -775,42 +745,6 @@ test.describe('Form Helper', () => {
await expect(errors.name).toBe('Some name error')
})

test('marks the form as no longer processing', async ({ page }) => {
await clickAndWaitForResponse(page, 'onError resets processing', 'form-helper/events/errors', 'button')

const messages = await page.evaluate(() => (window as any).events)
const data = await page.evaluate(() => (window as any).data)

await expect(messages).toEqual(['onBefore', 'onCancelToken', 'onStart', 'onError', 'onFinish'])

const processing = data.find((d) => d.event === 'onStart' && d.type === 'processing').data
const notProcessing = data.find((d) => d.event === 'onFinish' && d.type === 'processing').data

await expect(processing).toBe(true)
await expect(notProcessing).toBe(false)
})

test('resets the progress property back to null', async ({ page }) => {
await clickAndWaitForResponse(page, 'onError progress property', 'form-helper/events/errors', 'button')

const messages = await page.evaluate(() => (window as any).events)
const data = await page.evaluate(() => (window as any).data)

await expect(messages[3]).toBe('onProgress')

const event = data.find((d) => d.event === 'onProgress' && d.type === 'progress').data
const finishEvent = data.find((d) => d.event === 'onFinish' && d.type === 'progress').data

await expect(event).toHaveProperty('percentage')
await expect(event).toHaveProperty('total')
await expect(event).toHaveProperty('loaded')
await expect(event.percentage).toBeGreaterThanOrEqual(0)
await expect(event.percentage).toBeLessThanOrEqual(100)

await expect(messages[4]).toBe('onError')
await expect(finishEvent).toBeNull()
})

test('sets form errors', async ({ page }) => {
await clickAndWaitForResponse(page, 'Errors set on error', 'form-helper/events/errors', 'button')

Expand Down Expand Up @@ -854,6 +788,36 @@ test.describe('Form Helper', () => {

await expect(messages).toEqual(['onBefore', 'onCancelToken', 'onStart', 'onSuccess', 'onFinish'])
})

test('marks the form as no longer processing', async ({ page }) => {
await page.getByRole('button', { exact: true, name: 'onSuccess resets processing' }).click()

const data = await page.evaluate(() => (window as any).data)

const processing = data.find((d) => d.event === 'onStart' && d.type === 'processing').data
const notProcessing = data.find((d) => d.event === 'onFinish' && d.type === 'processing').data

await expect(processing).toBe(true)
await expect(notProcessing).toBe(false)
})

test('resets the progress property back to null', async ({ page }) => {
await clickAndWaitForResponse(page, 'onSuccess progress property', 'sleep', 'button')

const messages = await page.evaluate(() => (window as any).events)
const data = await page.evaluate(() => (window as any).data)
const event = data.find((d) => d.event === 'onProgress' && d.type === 'progress').data
const endEvent = data.find((d) => d.event === 'onFinish' && d.type === 'progress').data

await expect(event).toHaveProperty('percentage')
await expect(event).toHaveProperty('total')
await expect(event).toHaveProperty('loaded')
await expect(event.percentage).toBeGreaterThanOrEqual(0)
await expect(event.percentage).toBeLessThanOrEqual(100)

await expect(messages[4]).toBe('onFinish')
await expect(endEvent).toBeNull()
})
})
})
})
Expand Down