Aram Dulyan avatar Aram Dulyan committed e865554

Added hidden widget overriding for MarkupFields.
The hidden widget now correctly uses the raw, rather than rendered, value. This fixes issues when a MarkupField has a callable default (which triggers hidden widget rendering), resulting in unescaped HTML characters in the <input> value.

Comments (0)

Files changed (2)

markitup/fields.py

     def formfield(self, **kwargs):
         defaults = {'widget': widgets.MarkupTextarea}
         defaults.update(kwargs)
-        return super(MarkupField, self).formfield(**defaults)
+        field = super(MarkupField, self).formfield(**defaults)
+        field.hidden_widget = widgets.MarkupHiddenWidget
+        return field
 
 # register MarkupField to use the custom widget in the Admin
 from django.contrib.admin.options import FORMFIELD_FOR_DBFIELD_DEFAULTS

markitup/widgets.py

 from markitup.util import absolute_url
 import posixpath
 
-class MarkupTextarea(forms.Textarea):
+class MarkupInput(forms.Widget):
     def render(self, name, value, attrs=None):
         if value is not None:
             # Special handling for MarkupField value.
                 value = value.raw
             except AttributeError:
                 pass
-        return super(MarkupTextarea, self).render(name, value, attrs)
+        return super(MarkupInput, self).render(name, value, attrs)
+
+class MarkupTextarea(MarkupInput, forms.Textarea):
+    pass
+
+class MarkupHiddenWidget(MarkupInput, forms.HiddenInput):
+    pass
 
 
 class MarkItUpWidget(MarkupTextarea):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.