Skip to content

Commit

Permalink
Correctly handle noValueToken in RadioWidget
Browse files Browse the repository at this point in the history
For a RadioWidget which is not required the the '--NOVALUE--' token is
not handled correctly. This will not be part of self.terms. Handle this
case separately.
  • Loading branch information
gaudenz committed Nov 13, 2014
1 parent bec295e commit c77e243
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CHANGES
3.2.2 (unreleased)
------------------

- Nothing changed yet.
- Correctly handle noValueToken in RadioWidget


3.2.1 (2014-06-09)
Expand Down
13 changes: 11 additions & 2 deletions src/z3c/form/browser/radio.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import zope.schema
import zope.schema.interfaces
from zope.i18n import translate
from zope.schema.vocabulary import SimpleTerm
from zope.pagetemplate.interfaces import IPageTemplate

from z3c.form import interfaces, util
Expand All @@ -41,9 +42,17 @@ def isChecked(self, term):
return term.token in self.value

def renderForValue(self, value):
term = self.terms.getTermByToken(value)
terms = list(self.terms)
try:
term = self.terms.getTermByToken(value)
except LookupError:
if value == SequenceWidget.noValueToken:
term = SimpleTerm(value)
terms.insert(0, term)
else:
raise
checked = self.isChecked(term)
id = '%s-%i' % (self.id, list(self.terms).index(term))
id = '%s-%i' % (self.id, terms.index(term))
item = {'id': id, 'name': self.name, 'value': term.token,
'checked': checked}
template = zope.component.getMultiAdapter(
Expand Down

0 comments on commit c77e243

Please sign in to comment.