Skip to content
This repository has been archived by the owner on Aug 18, 2021. It is now read-only.

Commit

Permalink
Update the display value to be nicer for non js
Browse files Browse the repository at this point in the history
  • Loading branch information
Todd Dembrey committed Feb 8, 2018
1 parent c58edfd commit 924930d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% for widget in widget.subwidgets %}
{% if not widget.subwidgets %}
<div class="form__item">
<label for="{{ widget.attrs.id }}">{{ widget.attrs.class.title }}</label>
<label for="{{ widget.attrs.id }}">{{ widget.attrs.display }}</label>
{% endif %}

{% include widget.template_name %}
Expand Down
19 changes: 14 additions & 5 deletions addressfield/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,27 @@ class KeepAttrsTextInput(KeepOwnAttrsWidget, forms.TextInput):
pass


def classify(field):
return field.replace('_', '')


def display(field):
return field.replace('_', ' ').title()


class NestedMultiWidget(KeepOwnAttrsWidget, forms.MultiWidget):
template_name = 'addressfield/widgets/nested_with_label.html'

def __init__(self, *args, **kwargs):
widgets = [
widget(attrs={'class': field, 'required': False}) for field, widget in self.components.items()
widget(attrs={'class': classify(field), 'required': False, 'display': display(field)})
for field, widget in self.components.items()
]
super().__init__(widgets, *args, **kwargs)

@property
def field_names(self):
return list(self.components.keys())
return [classify(field) for field in self.components.keys()]

def decompress(self, value):
if value:
Expand All @@ -58,9 +67,9 @@ def value_from_datadict(self, data, files, name):

class LocalityWidget(NestedMultiWidget):
components = {
'localityname': KeepAttrsTextInput,
'administrativearea': KeepAttrsTextInput,
'postalcode': KeepAttrsTextInput,
'locality_name': KeepAttrsTextInput,
'administrative_area': KeepAttrsTextInput,
'postal_code': KeepAttrsTextInput,
}


Expand Down

0 comments on commit 924930d

Please sign in to comment.