Skip to content

Commit

Permalink
fix #146: Dialog forms with siblings
Browse files Browse the repository at this point in the history
Add demo to show how to use dialogs in collections with siblings
  • Loading branch information
jrief committed Sep 4, 2024
1 parent d424b8b commit e72e58c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
54 changes: 54 additions & 0 deletions testapp/forms/cafeteria.py
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()
4 changes: 4 additions & 0 deletions testapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
)
from testapp.forms.birthdate import BirthdateBoxForm, BirthdateCalendarForm, BirthdateInputForm, BirthdatePickerForm
from testapp.forms.booking import BookingBoxForm, BookingCalendarForm, BookingPickerForm
from testapp.forms.cafeteria import CafeteriaCollection
from testapp.forms.country import CountryForm
from testapp.forms.county import CountyForm
from testapp.forms.customer import CustomerCollection
Expand Down Expand Up @@ -573,6 +574,9 @@ class CompleteForm(FormMixin, forms.Form):
template_name='testapp/form-collection-no-buttons.html',
), name='simplecontact'),
path('issue', IssueCollectionView.as_view(), name='issue'),
path('cafeteria', DemoFormCollectionView.as_view(
collection_class=CafeteriaCollection,
), name='simplecontact'),
path('customer', DemoFormCollectionView.as_view(
collection_class=CustomerCollection,
), name='customer'),
Expand Down

0 comments on commit e72e58c

Please sign in to comment.