Skip to content

Commit

Permalink
RadioWidget items are better determined when they are needed
Browse files Browse the repository at this point in the history
  • Loading branch information
agroszer committed Feb 25, 2016
1 parent 4231cca commit dd40f6f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 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.10 (unreleased)
-------------------

- Nothing changed yet.
- RadioWidget items are better determined when they are needed [agroszer]


3.2.9 (2016-02-01)
Expand Down
25 changes: 12 additions & 13 deletions src/z3c/form/browser/radio.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class RadioWidget(widget.HTMLInputWidget, SequenceWidget):

klass = u'radio-widget'
css = u'radio'
items = ()

def isChecked(self, term):
return term.token in self.value
Expand All @@ -60,14 +59,9 @@ def renderForValue(self, value):
IPageTemplate, name=self.mode + '_single')
return template(self, item)

def update(self):
"""See z3c.form.interfaces.IWidget."""
super(RadioWidget, self).update()
# XXX: this is to early for setup items. See select widget how this
# sould be done. Setup the items here doens't allow to override the
# widget.value in updateWidgets, ri
widget.addFieldClass(self)
self.items = []
def items(self):
if self.terms is None:
return
for count, term in enumerate(self.terms):
checked = self.isChecked(term)
id = '%s-%i' % (self.id, count)
Expand All @@ -76,16 +70,21 @@ def update(self):
default=term.title)
else:
label = util.toUnicode(term.value)
self.items.append(
{'id':id, 'name':self.name, 'value':term.token,
'label':label, 'checked':checked})
yield {'id': id, 'name': self.name, 'value': term.token,
'label': label, 'checked': checked}

def update(self):
"""See z3c.form.interfaces.IWidget."""
super(RadioWidget, self).update()
widget.addFieldClass(self)

def json_data(self):
data = super(RadioWidget, self).json_data()
data['options'] = self.items
data['options'] = list(self.items())
data['type'] = 'radio'
return data


@zope.component.adapter(zope.schema.interfaces.IField, interfaces.IFormLayer)
@zope.interface.implementer(interfaces.IFieldWidget)
def RadioFieldWidget(field, request):
Expand Down
2 changes: 1 addition & 1 deletion src/z3c/form/browser/radio.txt
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ the value (which is used as a backup label) contains non-ASCII characters:
>>> terms = SimpleVocabulary.fromValues([b'yes\012', b'no\243'])
>>> widget.terms = terms
>>> widget.update()
>>> pprint(widget.items)
>>> pprint(list(widget.items()))
[{'checked': False,
'id': 'widget-id-0',
'label': 'yes\n',
Expand Down

0 comments on commit dd40f6f

Please sign in to comment.