-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
INT-268 Update documentation to include parent/child api
- Loading branch information
Showing
10 changed files
with
133 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Controller from '@ember/controller'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { action } from '@ember/object'; | ||
|
||
class User { | ||
@tracked name = 'user-1234'; | ||
} | ||
|
||
class Avatar { | ||
@tracked name = 'default'; | ||
} | ||
|
||
export default class AdvancedController extends Controller { | ||
@tracked user = new User(); | ||
@tracked avatar = new Avatar(); | ||
|
||
@action | ||
async handleSubmit() { | ||
alert(`Creating new user with username ${this.user.name}... user created!`); | ||
} | ||
|
||
@action | ||
async handleChildSubmit() { | ||
alert(`Updating avatar description to ${this.user.name}-${this.avatar.name}-avatar.jpeg... avatar description updated!`); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Advanced Use Cases | ||
|
||
## Child Forms | ||
|
||
Foxy Forms supports parent/child relationships to better separate concerns for more verbose scenarios. Calling submit on the parent will submit itself, and then call submit any children, breadth-first, afterward. | ||
|
||
**NOTE**: the parent form will only call submit on children with dirty fields. | ||
|
||
**Example: product onboarding** | ||
|
||
Let's say we want to collect a new user's information during an onboarding flow, and then optionally allow the 'default' part of the avatar name to be updated. We could have two forms: one responsible for collecting general account information, and another specific to handling avatar logic. | ||
|
||
{{#docs-demo as |demo|}} | ||
{{#demo.example name="advanced-usage.hbs"}} | ||
<Form | ||
@for={{this.user}} | ||
@onSubmit={{this.handleSubmit}} | ||
as |f|> | ||
<f.field | ||
@for="name" | ||
@using="input" | ||
@label="Username" | ||
/> | ||
<div style="border: 1px solid gray; padding: 0.5rem; margin: 1rem"> | ||
<strong>Optional: change avatar description?</strong> | ||
<Form | ||
@for={{this.avatar}} | ||
@parentForm={{f.self}} | ||
@onSubmit={{this.handleChildSubmit}} | ||
as |cf|> | ||
<div style="display: flex; align-items: center;"> | ||
{{this.user.name}}- | ||
<cf.field | ||
@for="name" | ||
@using="input" | ||
required | ||
/> | ||
-avatar.jpeg | ||
</div> | ||
</Form> | ||
</div> | ||
<f.submit @text="Submit form" /> | ||
</Form> | ||
{{/demo.example}} | ||
{{demo.snippet "advanced-usage.hbs"}} | ||
{{/docs-demo}} |
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