Skip to content

Commit

Permalink
Split out a method for rendering just the hidden input field HTML
Browse files Browse the repository at this point in the history
Fixes #24 - subclasses that override render_html now don't have to hack around the super() call.
  • Loading branch information
gasman committed Jul 22, 2021
1 parent 0522d08 commit 4c81096
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion generic_chooser/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ def get_value_data(self, value):
'edit_item_url': self.get_edit_item_url(instance),
}

def render_input_html(self, name, value, attrs):
# render the HTML for just the (hidden) input field
return super().render_html(name, value, attrs)

def render_html(self, name, value, attrs):
if WAGTAIL_VERSION >= (2, 12):
# From Wagtail 2.12, get_value_data is called as a preprocessing step in
Expand All @@ -133,7 +137,7 @@ def render_html(self, name, value, attrs):
else:
value_data = self.get_value_data(value)

original_field_html = super().render_html(name, value_data['value'], attrs)
original_field_html = self.render_input_html(name, value_data['value'], attrs)

return render_to_string(self.template, {
'widget': self,
Expand Down

0 comments on commit 4c81096

Please sign in to comment.