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:
parent
c0c0f941eb
commit
d0ff3fecea
3 changed files with 28 additions and 20 deletions
|
@ -33,7 +33,6 @@ const form = new FormGroup([
|
|||
name: 'rating',
|
||||
label: 'Rating',
|
||||
type: 'radio',
|
||||
value: '5',
|
||||
options: ['1', '2', '3', '4', '5'],
|
||||
},
|
||||
{
|
||||
|
@ -71,19 +70,22 @@ form.name = 'Simple Form';
|
|||
|
||||
const config: ControlConfig = {
|
||||
type: 'checkbox',
|
||||
name: 'is-awesome',
|
||||
name: 'isAwesome',
|
||||
label: 'is Awesome?',
|
||||
};
|
||||
|
||||
// insert a control
|
||||
form.controls.push(new FormControl(config));
|
||||
|
||||
// get the FormControl object
|
||||
const userNameControl = form.get('username');
|
||||
// set the value of multiple controls
|
||||
form.setValue({
|
||||
username: 'RAMOOOON',
|
||||
isAwesome: 'checked',
|
||||
});
|
||||
|
||||
// set values dynamically
|
||||
userNameControl?.setValue('RAMOOOON');
|
||||
form.get('is-awesome')?.setValue('checked');
|
||||
// set the value of a specific control
|
||||
const ratingControl = form.get('rating');
|
||||
ratingControl?.setValue('5');
|
||||
|
||||
// setting an invalid value will cause errors as server-rendered
|
||||
form.get('email')?.setValue('invalid-email');
|
||||
|
|
|
@ -49,40 +49,44 @@ const form = new FormGroup([
|
|||
},
|
||||
]);
|
||||
|
||||
// set the name optionally
|
||||
form.name = "Simple Form";
|
||||
|
||||
// you can insert a control at any point
|
||||
form.controls.push(
|
||||
new FormControl({
|
||||
type: "checkbox",
|
||||
name: "is-awesome",
|
||||
name: "isAwesome",
|
||||
label: "is Awesome?",
|
||||
})
|
||||
);
|
||||
|
||||
// set the value of multiple controls
|
||||
form.setValue({
|
||||
username: 'DEFAULT',
|
||||
isAwesome: 'checked',
|
||||
});
|
||||
|
||||
// you can get a FormControl object
|
||||
const userNameControl = form.get("username");
|
||||
|
||||
// you can set values dynamically
|
||||
// you can set the value of specific control
|
||||
userNameControl?.setValue("RAMOOOON");
|
||||
form.get('is-awesome')?.setValue("checked");
|
||||
|
||||
---
|
||||
|
||||
<Form
|
||||
formGroups={form}
|
||||
validateOnLoad
|
||||
showValidationHints
|
||||
action="/submission"
|
||||
method="post"
|
||||
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
|
||||
Result of example above:
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||

|
||||
|
|
Loading…
Reference in a new issue