-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
- Loading branch information
There are no files selected for viewing
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!`); | ||
Check failure on line 24 in tests/dummy/app/controllers/docs/advanced.js
|
||
} | ||
} |
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}} |