Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: form state (ASPX) #3

Merged
merged 3 commits into from
Dec 24, 2023
Merged
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
1 change: 0 additions & 1 deletion examples/simple-form/src/pages/button.astro
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Layout from '../layouts/Layout.astro';


let showSubmitText: string;

function formSubmit() {
Astro.locals.session.counter ??= 0;
Astro.locals.session.counter++;
Expand Down
22 changes: 20 additions & 2 deletions examples/simple-form/src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,35 @@ import {Button} from 'reactstrap';
import 'bootstrap/dist/css/bootstrap.css';


const form = Bind({age: 0, name: ''});
const form = Bind({age: 0, name: '', about: ''});
let showSubmitText: string;

function formSubmit(){
Astro.locals.session.counter ??= 0;
Astro.locals.session.counter++;
showSubmitText = `Your name is ${form.name}, you are ${form.age} years old. `;
form.age++;
}

let value = 4;
function makeBackgroundRed() {
this.style = 'background-color: red';
value = 5;
this.innerHTML = 'Clicked ' + (++this.extra || ++this.state.counter);
form.about = 'This is a form about something';
}
---
<Layout title="Form + Session">
<BindForm bind={form}>
<BButton props={{color: 'info'}} onClick={makeBackgroundRed} extra={1}>Should click</BButton>

<BindForm bind={form} state={['about']}>
{[1, 2, 3].map(key =>
<BButton props={{color: 'info'}} onClick={makeBackgroundRed} state={{counter: key}}>Should click</BButton>
)}

<p>Value: {value}</p>
<p>About: {form.about}</p>

<FormErrors/>
{showSubmitText}

Expand Down
Loading