Skip to content
Snippets Groups Projects
Commit 94d16e30 authored by Todd Dembrey's avatar Todd Dembrey
Browse files

Update to ensure processing of the submitted value

parent df4d3c0e
No related branches found
No related tags found
No related merge requests found
...@@ -8,13 +8,13 @@ ...@@ -8,13 +8,13 @@
$('.form div.address').addressfield({ $('.form div.address').addressfield({
json: '/static/addressfield.min.json', json: '/static/addressfield.min.json',
fields: { fields: {
country: "[name='country']", country: ".country",
thoroughfare: "[name='address_1']", thoroughfare: ".thoroughfare",
premise: "[name='address_2']", premise: ".premise",
locality: "[name='locality']", locality: ".locality",
localityname: "[name='city']", localityname: ".localityname",
administrativearea: "[name='state']", administrativearea: ".administrativearea",
postalcode: "[name='zip']" postalcode: ".postalcode"
} }
}); });
}); });
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
{% for widget in widget.subwidgets %} {% for widget in widget.subwidgets %}
{% if not widget.subwidgets %} {% if not widget.subwidgets %}
<div class="form__item"> <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 %} {% endif %}
{% include widget.template_name %} {% include widget.template_name %}
......
...@@ -6,7 +6,6 @@ from django_countries import countries ...@@ -6,7 +6,6 @@ from django_countries import countries
class KeepOwnAttrsWidget(forms.Widget): class KeepOwnAttrsWidget(forms.Widget):
def get_context(self, name, value, attrs): def get_context(self, name, value, attrs):
name = self.attrs.get('name') or name
attrs.update(self.attrs) attrs.update(self.attrs)
return super().get_context(name, value, attrs) return super().get_context(name, value, attrs)
...@@ -21,12 +20,12 @@ class KeepAttrsTextInput(KeepOwnAttrsWidget, forms.TextInput): ...@@ -21,12 +20,12 @@ class KeepAttrsTextInput(KeepOwnAttrsWidget, forms.TextInput):
pass pass
class NestedMultiWidget(forms.MultiWidget): class NestedMultiWidget(KeepOwnAttrsWidget, forms.MultiWidget):
template_name = 'funds/widgets/nested_with_label.html' template_name = 'funds/widgets/nested_with_label.html'
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
widgets = [ 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) super().__init__(widgets, *args, **kwargs)
...@@ -36,8 +35,9 @@ class NestedMultiWidget(forms.MultiWidget): ...@@ -36,8 +35,9 @@ class NestedMultiWidget(forms.MultiWidget):
return [None] * len(self.components) return [None] * len(self.components)
def value_from_datadict(self, data, files, name): def value_from_datadict(self, data, files, name):
field_names = list(self.components.keys())
return { 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) for i, widget in enumerate(self.widgets)
} }
...@@ -45,9 +45,9 @@ class NestedMultiWidget(forms.MultiWidget): ...@@ -45,9 +45,9 @@ class NestedMultiWidget(forms.MultiWidget):
class LocalityWidget(NestedMultiWidget): class LocalityWidget(NestedMultiWidget):
components = { components = {
'city': KeepAttrsTextInput, 'localityname': KeepAttrsTextInput,
'state': KeepAttrsTextInput, 'administrativearea': KeepAttrsTextInput,
'zip': KeepAttrsTextInput, 'postalcode': KeepAttrsTextInput,
} }
...@@ -55,8 +55,8 @@ class LocalityWidget(NestedMultiWidget): ...@@ -55,8 +55,8 @@ class LocalityWidget(NestedMultiWidget):
class AddressWidget(NestedMultiWidget): class AddressWidget(NestedMultiWidget):
components = { components = {
'country': CountrySelectWithChoices, 'country': CountrySelectWithChoices,
'address_1': KeepAttrsTextInput, 'thoroughfare': KeepAttrsTextInput,
'address_2': KeepAttrsTextInput, 'premise': KeepAttrsTextInput,
'locality': LocalityWidget, 'locality': LocalityWidget,
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment