-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #146: Dialog forms with siblings
Add demo to show how to use dialogs in collections with siblings
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from django.forms.fields import CharField, ChoiceField | ||
from django.forms.forms import Form | ||
from django.forms.widgets import RadioSelect | ||
from formset.collection import FormCollection | ||
from formset.dialog import ApplyButton, CancelButton, DialogForm | ||
from formset.fields import Activator | ||
|
||
|
||
class CoffeeForm(Form): | ||
nickname = CharField() | ||
flavors = Activator( | ||
label="Add flavors", | ||
help_text="Open the dialog to edit flavors", | ||
) | ||
|
||
|
||
class FlavorForm(DialogForm): | ||
title = "Choose a Flavor" | ||
induce_open = '..coffee.flavors:active' | ||
induce_close = '.cancel:active || .apply:active' | ||
|
||
flavors = ChoiceField( | ||
choices=( | ||
('caramel', "Caramel Macchiato"), | ||
('cinnamon', "Cinnamon Dolce Latte"), | ||
('hazelnut', "Turkish Hazelnut"), | ||
('vanilla', "Vanilla Latte"), | ||
('chocolate', "Chocolate Fudge"), | ||
('almonds', "Roasted Almonds"), | ||
('cream', "Irish Cream"), | ||
), | ||
widget=RadioSelect, | ||
required=False, | ||
) | ||
cancel = Activator( | ||
label="Close", | ||
widget=CancelButton, | ||
) | ||
apply = Activator( | ||
label="Apply", | ||
widget=ApplyButton, | ||
) | ||
|
||
class CoffeeOrderCollection(FormCollection): | ||
legend = "Order your coffee" | ||
add_label = "Add Coffee Order" | ||
min_siblings = 1 | ||
extra_siblings = 1 | ||
coffee = CoffeeForm() | ||
flavor = FlavorForm() | ||
|
||
|
||
class CafeteriaCollection(FormCollection): | ||
coffee_order = CoffeeOrderCollection() |
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