docs: update example in form readme (#258)

* docs: update example in form readme

* chore: update readme

* chore: update validator readme
This commit is contained in:
Ayo Ayco 2023-02-01 17:16:03 +01:00 committed by GitHub
parent c0c0f941eb
commit d0ff3fecea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 20 deletions

View file

@ -33,7 +33,6 @@ const form = new FormGroup([
name: 'rating', name: 'rating',
label: 'Rating', label: 'Rating',
type: 'radio', type: 'radio',
value: '5',
options: ['1', '2', '3', '4', '5'], options: ['1', '2', '3', '4', '5'],
}, },
{ {
@ -71,19 +70,22 @@ form.name = 'Simple Form';
const config: ControlConfig = { const config: ControlConfig = {
type: 'checkbox', type: 'checkbox',
name: 'is-awesome', name: 'isAwesome',
label: 'is Awesome?', label: 'is Awesome?',
}; };
// insert a control // insert a control
form.controls.push(new FormControl(config)); form.controls.push(new FormControl(config));
// get the FormControl object // set the value of multiple controls
const userNameControl = form.get('username'); form.setValue({
username: 'RAMOOOON',
isAwesome: 'checked',
});
// set values dynamically // set the value of a specific control
userNameControl?.setValue('RAMOOOON'); const ratingControl = form.get('rating');
form.get('is-awesome')?.setValue('checked'); ratingControl?.setValue('5');
// setting an invalid value will cause errors as server-rendered // setting an invalid value will cause errors as server-rendered
form.get('email')?.setValue('invalid-email'); form.get('email')?.setValue('invalid-email');

View file

@ -49,40 +49,44 @@ const form = new FormGroup([
}, },
]); ]);
// set the name optionally
form.name = "Simple Form";
// you can insert a control at any point // you can insert a control at any point
form.controls.push( form.controls.push(
new FormControl({ new FormControl({
type: "checkbox", type: "checkbox",
name: "is-awesome", name: "isAwesome",
label: "is Awesome?", label: "is Awesome?",
}) })
); );
// set the value of multiple controls
form.setValue({
username: 'DEFAULT',
isAwesome: 'checked',
});
// you can get a FormControl object // you can get a FormControl object
const userNameControl = form.get("username"); const userNameControl = form.get("username");
// you can set values dynamically // you can set the value of specific control
userNameControl?.setValue("RAMOOOON"); userNameControl?.setValue("RAMOOOON");
form.get('is-awesome')?.setValue("checked");
--- ---
<Form <Form
formGroups={form} formGroups={form}
validateOnLoad
showValidationHints
action="/submission"
method="post"
submitControl={{ submitControl={{
type: "submit", name: 'submit',
name: "submit", type: 'submit',
}} }}
/> />
<!--
The `formGroups` attribute can take a single FormGroup
or an array of FormGroup for multiple fieldset blocks;
we are using a single FormGroup for now in this example.
-->
``` ```
👉 For more examples and explanations of the component properties, see the [Form API Docs](https://docs.astro-reactive.dev/en/api/form/form-component/).
# Screenshots # Screenshots
Result of example above: Result of example above:

View file

@ -80,6 +80,8 @@ form.controls.push(
--> -->
``` ```
👉 For more examples and explanations of the component properties, see the [Validators API Docs](https://docs.astro-reactive.dev/en/api/validator/validators/).
# Screenshots # Screenshots
![Screen Shot 2022-10-15 at 1 31 11 PM](https://user-images.githubusercontent.com/4262489/195984173-c19e8cf0-bc55-41d5-8267-e3de44c6bf64.png) ![Screen Shot 2022-10-15 at 1 31 11 PM](https://user-images.githubusercontent.com/4262489/195984173-c19e8cf0-bc55-41d5-8267-e3de44c6bf64.png)