-
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.
submit/reset buttons can be added to Forms and Collections
- Loading branch information
Showing
6 changed files
with
101 additions
and
7 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,62 @@ | ||
from django.forms import fields, forms | ||
from django.utils.safestring import mark_safe | ||
|
||
from formset.collection import FormCollection | ||
from formset.dialog import ApplyButton, CancelButton, DialogForm | ||
from formset.fields import Activator | ||
from formset.renderers import ButtonVariant | ||
from formset.widgets import Button | ||
|
||
|
||
class AcceptDialogForm(DialogForm): | ||
title = "Terms of Use" | ||
epilogue = mark_safe(""" | ||
<p>This site does not allow content or activity that:</p> | ||
<ul> | ||
<li>is unlawful or promotes violence.</li> | ||
<li>shows sexual exploitation or abuse.</li> | ||
<li>harasses, defames or defrauds other users.</li> | ||
<li>is discriminatory against other groups of users.</li> | ||
<li>violates the privacy of other users.</li> | ||
</ul> | ||
<p>Before proceeding, please accept the terms of use.</p> | ||
""") | ||
induce_open = 'submit:active' | ||
induce_close = '.close:active' | ||
close = Activator( | ||
label="Close", | ||
widget=CancelButton, | ||
) | ||
|
||
|
||
class UserNameForm(forms.Form): | ||
full_name = fields.CharField( | ||
label="Full Name", | ||
max_length=100, | ||
) | ||
accept_terms = fields.BooleanField( | ||
label="Accept terms of use", | ||
required=False, | ||
) | ||
|
||
|
||
class AcceptTermsCollection(FormCollection): | ||
legend = "User Acceptance Collection" | ||
user = UserNameForm() | ||
accept = AcceptDialogForm() | ||
submit = Activator( | ||
label="Submit", | ||
widget=Button( | ||
action='user.accept_terms ? disable -> submit -> reload !~ scrollToError : activate', | ||
button_variant=ButtonVariant.PRIMARY, | ||
icon_path='formset/icons/send.svg', | ||
), | ||
) | ||
reset = Activator( | ||
label="Reset to initial", | ||
widget=Button( | ||
action='reset', | ||
button_variant=ButtonVariant.WARNING, | ||
icon_path='formset/icons/reset.svg', | ||
), | ||
) |
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,7 @@ | ||
{% extends framework|default:"testapp"|add:"/base.html" %} | ||
|
||
{% block main-content %} | ||
<django-formset endpoint="{{ request.path }}"{% if force_submission %} force-submission{% endif %}{% if withhold_feedback %} withhold-feedback="{{ withhold_feedback }}"{% endif %} csrf-token="{{ csrf_token }}"> | ||
{{ form_collection }} | ||
</django-formset> | ||
{% endblock %} |
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,8 @@ | ||
{% extends framework|default:"testapp"|add:"/base.html" %} | ||
{% load render_form from formsetify %} | ||
|
||
{% block main-content %} | ||
<django-formset endpoint="{{ request.path }}"{% if force_submission %} force-submission{% endif %}{% if withhold_feedback %} withhold-feedback="{{ withhold_feedback }}"{% endif %} csrf-token="{{ csrf_token }}"> | ||
{% render_form form framework form_classes=form_css_classes field_classes=field_css_classes fieldset_classes=fieldset_css_classes label_classes=label_css_classes|default:None control_classes=control_css_classes %} | ||
</django-formset> | ||
{% endblock %} |
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