forked from QwikDev/qwik
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ff32c5
commit 71b252f
Showing
25 changed files
with
176 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,33 @@ | ||
import type { ServerActionUse } from './server-functions'; | ||
import { jsx, _wrapSignal, QwikJSX } from '@builder.io/qwik'; | ||
import { jsx, _wrapSignal, QwikJSX, PropFunction } from '@builder.io/qwik'; | ||
|
||
/** | ||
* @alpha | ||
*/ | ||
export interface FormProps<T> extends Omit<QwikJSX.IntrinsicElements['form'], 'action'> { | ||
action: ServerActionUse<T>; | ||
method?: 'post'; | ||
onSubmit$?: PropFunction<(event: Event) => void>; | ||
reloadDocument?: boolean; | ||
spaReset?: boolean; | ||
} | ||
|
||
/** | ||
* @alpha | ||
*/ | ||
export const Form = <T,>({ action, ...rest }: FormProps<T>) => { | ||
export const Form = <T,>({ | ||
action, | ||
spaReset, | ||
reloadDocument, | ||
onSubmit$, | ||
...rest | ||
}: FormProps<T>) => { | ||
return jsx('form', { | ||
action: action.actionPath, | ||
'preventdefault:submit': true, | ||
onSubmit$: action.run, | ||
...rest, | ||
action: action.actionPath, | ||
'preventdefault:submit': !reloadDocument, | ||
onSubmit$: [!reloadDocument ? action.run : undefined, onSubmit$], | ||
method: 'post', | ||
['data-spa-reset']: spaReset ? 'true' : undefined, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
starters/apps/qwikcity-test/src/routes/(common)/issue2644/data.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const data: string[] = []; |
19 changes: 19 additions & 0 deletions
19
starters/apps/qwikcity-test/src/routes/(common)/issue2644/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { component$ } from '@builder.io/qwik'; | ||
import { action$, Form } from '@builder.io/qwik-city'; | ||
import { data } from './data'; | ||
|
||
export const rootAction = action$((form, { redirect }) => { | ||
const name = form.get('name'); | ||
data.push(name as string); | ||
throw redirect(303, '/qwikcity-test/issue2644/other/'); | ||
}); | ||
|
||
export default component$(() => { | ||
const action = rootAction.use(); | ||
return ( | ||
<Form action={action}> | ||
<input name="name" id="issue2644-input" /> | ||
<button id="issue2644-submit">Submit</button> | ||
</Form> | ||
); | ||
}); |
31 changes: 31 additions & 0 deletions
31
starters/apps/qwikcity-test/src/routes/(common)/issue2644/other/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { component$ } from '@builder.io/qwik'; | ||
import { action$, loader$, Form } from '@builder.io/qwik-city'; | ||
import { data } from '../data'; | ||
|
||
export const getData = loader$(() => { | ||
return data; | ||
}); | ||
|
||
export const otherAction = action$((form) => { | ||
const name = form.get('name'); | ||
data.push(name as string); | ||
return { success: true }; | ||
}); | ||
|
||
export default component$(() => { | ||
const items = getData.use(); | ||
const action = otherAction.use(); | ||
return ( | ||
<div> | ||
<ul id="issue2644-list"> | ||
{items.value.map((x) => ( | ||
<li>{x}</li> | ||
))} | ||
</ul> | ||
<Form action={action}> | ||
<input name="name" id="issue2644-input" /> | ||
<button id="issue2644-submit">Submit</button> | ||
</Form> | ||
</div> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { expect, test } from '@playwright/test'; | ||
|
||
test.describe('loaders', () => { | ||
test.describe('mpa', () => { | ||
test.use({ javaScriptEnabled: false }); | ||
tests(); | ||
}); | ||
|
||
test.describe('spa', () => { | ||
test.use({ javaScriptEnabled: true }); | ||
tests(); | ||
}); | ||
|
||
function tests() { | ||
test.describe('issue2644', () => { | ||
test('should submit items', async ({ page }) => { | ||
await page.goto('/qwikcity-test/issue2644/'); | ||
await page.locator('#issue2644-input').fill('AAA'); | ||
await page.locator('#issue2644-submit').click(); | ||
await page.waitForTimeout(200); | ||
|
||
const pageUrl = new URL(page.url()); | ||
await expect(pageUrl.pathname).toBe('/qwikcity-test/issue2644/other/'); | ||
await expect(page.locator('#issue2644-list > li')).toHaveText(['AAA']); | ||
|
||
await page.locator('#issue2644-input').fill('BBB'); | ||
await page.locator('#issue2644-submit').click(); | ||
await expect(pageUrl.pathname).toBe('/qwikcity-test/issue2644/other/'); | ||
|
||
await expect(page.locator('#issue2644-list > li')).toHaveText(['AAA', 'BBB']); | ||
}); | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.