From 94d16e303d2bab2be0358f4c2ea007af76e5846b Mon Sep 17 00:00:00 2001 From: Todd Dembrey <todd.dembrey@torchbox.com> Date: Wed, 31 Jan 2018 11:33:09 +0000 Subject: [PATCH] Update to ensure processing of the submitted value --- opentech/apply/funds/static/address_form.js | 14 +++++++------- .../funds/widgets/nested_with_label.html | 2 +- opentech/apply/funds/widgets.py | 18 +++++++++--------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/opentech/apply/funds/static/address_form.js b/opentech/apply/funds/static/address_form.js index 7843a3ae3..5ca770753 100644 --- a/opentech/apply/funds/static/address_form.js +++ b/opentech/apply/funds/static/address_form.js @@ -8,13 +8,13 @@ $('.form div.address').addressfield({ json: '/static/addressfield.min.json', fields: { - country: "[name='country']", - thoroughfare: "[name='address_1']", - premise: "[name='address_2']", - locality: "[name='locality']", - localityname: "[name='city']", - administrativearea: "[name='state']", - postalcode: "[name='zip']" + country: ".country", + thoroughfare: ".thoroughfare", + premise: ".premise", + locality: ".locality", + localityname: ".localityname", + administrativearea: ".administrativearea", + postalcode: ".postalcode" } }); }); diff --git a/opentech/apply/funds/templates/funds/widgets/nested_with_label.html b/opentech/apply/funds/templates/funds/widgets/nested_with_label.html index c1c7d0d48..d3e88f4c9 100644 --- a/opentech/apply/funds/templates/funds/widgets/nested_with_label.html +++ b/opentech/apply/funds/templates/funds/widgets/nested_with_label.html @@ -2,7 +2,7 @@ {% for widget in widget.subwidgets %} {% if not widget.subwidgets %} <div class="form__item"> - <label for="{{ widget.attrs.id }}">{{ widget.attrs.name.title }}</label> + <label for="{{ widget.attrs.id }}">{{ widget.attrs.class.title }}</label> {% endif %} {% include widget.template_name %} diff --git a/opentech/apply/funds/widgets.py b/opentech/apply/funds/widgets.py index 78b3ec452..4a08d10c8 100644 --- a/opentech/apply/funds/widgets.py +++ b/opentech/apply/funds/widgets.py @@ -6,7 +6,6 @@ from django_countries import countries class KeepOwnAttrsWidget(forms.Widget): def get_context(self, name, value, attrs): - name = self.attrs.get('name') or name attrs.update(self.attrs) return super().get_context(name, value, attrs) @@ -21,12 +20,12 @@ class KeepAttrsTextInput(KeepOwnAttrsWidget, forms.TextInput): pass -class NestedMultiWidget(forms.MultiWidget): +class NestedMultiWidget(KeepOwnAttrsWidget, forms.MultiWidget): template_name = 'funds/widgets/nested_with_label.html' def __init__(self, *args, **kwargs): widgets = [ - widget(attrs={'name': field}) for field, widget in self.components.items() + widget(attrs={'class': field}) for field, widget in self.components.items() ] super().__init__(widgets, *args, **kwargs) @@ -36,8 +35,9 @@ class NestedMultiWidget(forms.MultiWidget): return [None] * len(self.components) def value_from_datadict(self, data, files, name): + field_names = list(self.components.keys()) return { - widget.value_from_datadict(data, files, name + '_%s' % i) + field_names[i]: widget.value_from_datadict(data, files, name + '_%s' % i) for i, widget in enumerate(self.widgets) } @@ -45,9 +45,9 @@ class NestedMultiWidget(forms.MultiWidget): class LocalityWidget(NestedMultiWidget): components = { - 'city': KeepAttrsTextInput, - 'state': KeepAttrsTextInput, - 'zip': KeepAttrsTextInput, + 'localityname': KeepAttrsTextInput, + 'administrativearea': KeepAttrsTextInput, + 'postalcode': KeepAttrsTextInput, } @@ -55,8 +55,8 @@ class LocalityWidget(NestedMultiWidget): class AddressWidget(NestedMultiWidget): components = { 'country': CountrySelectWithChoices, - 'address_1': KeepAttrsTextInput, - 'address_2': KeepAttrsTextInput, + 'thoroughfare': KeepAttrsTextInput, + 'premise': KeepAttrsTextInput, 'locality': LocalityWidget, } -- GitLab