Skip to content

Commit

Permalink
feat: form state (ASPX) (#3)
Browse files Browse the repository at this point in the history
* fix: remove formidable deps

* feat: button pass props to onClick

* feat: view-state
  • Loading branch information
ido-pluto committed Dec 24, 2023
1 parent e4adc5d commit 1f71d80
Show file tree
Hide file tree
Showing 39 changed files with 974 additions and 355 deletions.
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

0 comments on commit 1f71d80

Please sign in to comment.