diff --git a/opentech/apply/funds/static/address_form.js b/opentech/apply/funds/static/address_form.js index 7843a3ae3ab70a19166e73b6a005515daf8a334f..5ca7707531f1f0b0f360539a4d503e6411853940 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 c1c7d0d48c7fe57cc9bcc60dc907cb1e1d09154f..d3e88f4c955edfbec21e59c4d543a331418870ac 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 78b3ec452b75e4ec17a6c42d9289afdc01cf9e68..4a08d10c81578be888739bdf74050b799ea92776 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, }