#7 MultiCheckboxField defaults are "forgotten" in invalid forms

open
nobody
None
5
2003-04-10
2003-04-09
Stefan Schwarzer
No

The patch regards MultiSelectFieldMixin.selected. The
current implementation fails, if the keys from the
original selection to build the checkboxes are strings.
I suggest the following implementation (copy from HTML
source view)::

def selected(self, key, default):
"""Return true if the selection's key matches
the default(s)."""
if isinstance(default, StringType):
return default and str(key) == str(default)
else:
# make rebinding to new name explicit
default_ = map(str, default)
return default_ and str(key) in default_

Stefan

Discussion

    • summary: MultiCheckboxField defaults are "forgotten" in invalid forms --> MultiCheckboxField defaults are "forgotten" in invalid forms
     
  • Logged In: YES
    user_id=383516

    Another approach is to convert the first "column" in every
    selection to strings. This would mean to modify
    SelectField.__init__ in Field.py:

    # current code
    self._selections = selections or []

    # change to
    selections = selections or []
    self._selections = [ (str(key), value) for (key, value) in
    selections ]