From 014c7d5db0041d955a6a4d86b2acad5205afa464 Mon Sep 17 00:00:00 2001 From: Todd Dembrey <todd.dembrey@torchbox.com> Date: Wed, 31 Jan 2018 11:55:35 +0000 Subject: [PATCH] Make the address field required on the form, but allow blank input --- opentech/apply/funds/blocks.py | 19 ++++++++++--------- opentech/apply/funds/widgets.py | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/opentech/apply/funds/blocks.py b/opentech/apply/funds/blocks.py index 911c1ade3..e14d6b0b5 100644 --- a/opentech/apply/funds/blocks.py +++ b/opentech/apply/funds/blocks.py @@ -47,17 +47,8 @@ class RichTextFieldBlock(TextFieldBlock): icon = 'form' -class AddressFieldBlock(OptionalFormFieldBlock): - widget = AddressWidget - - class Meta: - label = _('Address') - icon = 'home' - - class CustomFormFieldsBlock(FormFieldsBlock): rich_text = RichTextFieldBlock(group=_('Fields')) - address = AddressFieldBlock(group=_('Fields')) category = CategoryQuestionBlock(group=_('Custom')) def __init__(self, *args, **kwargs): @@ -172,6 +163,16 @@ class EmailBlock(MustIncludeFieldBlock): icon = 'mail' +class AddressFieldBlock(MustIncludeFieldBlock): + name = 'address' + description = 'The postal address of the user' + widget = AddressWidget + + class Meta: + label = _('Address') + icon = 'home' + + class FullNameBlock(MustIncludeFieldBlock): name = 'full_name' description = 'Full name' diff --git a/opentech/apply/funds/widgets.py b/opentech/apply/funds/widgets.py index a9cda6fc7..99b9c9e6c 100644 --- a/opentech/apply/funds/widgets.py +++ b/opentech/apply/funds/widgets.py @@ -25,7 +25,7 @@ class NestedMultiWidget(KeepOwnAttrsWidget, forms.MultiWidget): def __init__(self, *args, **kwargs): widgets = [ - widget(attrs={'class': field}) for field, widget in self.components.items() + widget(attrs={'class': field, 'required': False}) for field, widget in self.components.items() ] super().__init__(widgets, *args, **kwargs) -- GitLab