Jon Nelson
2009-10-08 17:18:22 UTC
I learned that htmlfill.render ignores <option> elements entirely if
force_defaults is False.
Here is a (working but probably wrong) patch to fix it, as applied to trunk.
diff --git a/formencode/htmlfill.py b/formencode/htmlfill.py
index b725f00..deb85eb 100644
--- a/formencode/htmlfill.py
+++ b/formencode/htmlfill.py
@@ -490,6 +490,13 @@ class FillingParser(RewritingParser):
self.add_key(self.in_select)
else:
self.del_attr(attrs, 'selected')
+ else:
+ value = self.defaults.get(self.in_select)
+ current = self.get_attr(attrs, 'value')
+ selected = self.get_attr(attrs, 'selected')
+ if selected is None and current is not None and value
is not None:
+ if self.selected_multiple(value, current):
+ self.set_attr(attrs, 'selected', 'selected')
self.write_tag('option', attrs)
self.skip_next = True
force_defaults is False.
Here is a (working but probably wrong) patch to fix it, as applied to trunk.
diff --git a/formencode/htmlfill.py b/formencode/htmlfill.py
index b725f00..deb85eb 100644
--- a/formencode/htmlfill.py
+++ b/formencode/htmlfill.py
@@ -490,6 +490,13 @@ class FillingParser(RewritingParser):
self.add_key(self.in_select)
else:
self.del_attr(attrs, 'selected')
+ else:
+ value = self.defaults.get(self.in_select)
+ current = self.get_attr(attrs, 'value')
+ selected = self.get_attr(attrs, 'selected')
+ if selected is None and current is not None and value
is not None:
+ if self.selected_multiple(value, current):
+ self.set_attr(attrs, 'selected', 'selected')
self.write_tag('option', attrs)
self.skip_next = True
--
Jon
Jon