Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #1314 (closed defect: fixed)

Opened 11 years ago

Last modified 8 years ago

SelectionField does not format values being rendered in template

Reported by: rick446 Owned by: anonymous
Priority: normal Milestone: 1.1.1
Component: TG Widgets Version: 1.0.4b3
Severity: normal Keywords: needs confirmation
Cc:

Description

As documented in  this thread, the SelectionField "values" parameter expects a list of the form [(value, display, attrs)] where value is a "Python" value, in the FormEncode sense. The template, then, should render that value to the <option> list using the SelectionField validator's from_python method. Furthermore, when a SelectionField is checking to see if a particular option is selected, it should not do any validator conversion, since it is comparing two "Python" values.

I have attached a patch (with a test) which converts outgoing SelectionField values and sets the "selected" attribute on the options correctly.

Attachments

selection_field_patch.diff Download (3.5 KB) - added by rick446 11 years ago.
Patch to turbogears/widgets/forms.py and turbogears/widgets/tests/test_widgets.py

Change History

Changed 11 years ago by rick446

Patch to turbogears/widgets/forms.py and turbogears/widgets/tests/test_widgets.py

comment:1 Changed 11 years ago by alberto

  • Status changed from new to closed
  • Resolution set to fixed

I've applied your patch but modified it in order not no remove the to_python conversion in _is_option_selected because it is needed when form redisplays itself because of errors as the value is a string in thta case while options are still python values.

Thanks :)

Alberto

comment:2 Changed 11 years ago by alberto

BTW, applied at [2843]

comment:3 Changed 11 years ago by alberto

  • Status changed from closed to reopened
  • Resolution fixed deleted

I had to revert this patch in [2862]. See this  thread for more info.

Alberto

comment:4 Changed 11 years ago by alberto

  • Summary changed from [PATCH] SelectionField does not format values being rendered in template to SelectionField does not format values being rendered in template

comment:5 Changed 11 years ago by alberto

  • Milestone changed from 1.0.2 to 1.0.3

comment:6 Changed 10 years ago by faide

  • Milestone changed from 1.0.3 to 1.1

comment:7 Changed 10 years ago by Chris Arndt

  • Version changed from trunk to 1.0.4b3

comment:8 Changed 9 years ago by Chris Arndt

  • Priority changed from normal to low

Setting this to low priority, because TG is moving to toscawidgets in the future.

comment:9 Changed 9 years ago by faide

  • Milestone changed from 1.5 to 1.1

comment:10 Changed 9 years ago by faide

  • Milestone changed from 1.1 to 1.1 maintenance

comment:11 Changed 8 years ago by Chris Arndt

  • Priority changed from low to normal
  • Keywords needs confirmation added
  • Milestone changed from 1.1.x bugfix to 1.1.1

We need to check if this is still an issue.

comment:12 Changed 8 years ago by chrisz

  • Status changed from reopened to closed
  • Resolution set to fixed

I have reapplied this patch in r6960, with additional provisions and a new unit test for empty values. This fixed the problem discussed in  this thread mentioned by Alberto in comment 3.

comment:13 Changed 8 years ago by chrisz

Just for the records, the patch in r6960 had two problems which have been fixed now:

1) A value of 0 was not handled properly (see #2418).

2) As Alberto already mentioned in the beginning, the to_python conversion in _is_option_selected is actually necessary and should not be removed. This has been added back in r6973 with the improvement that to_python is now only carried out when the values are really strings (e.g. in the case mentioned by Alberto, when a form with errors in it is re-displayed).

I have also added regression tests for these issues.

comment:14 Changed 8 years ago by chrisz

Another improvement was made in r6974 to make this work with sets as values of MultipleSelectFields as well.

Note: See TracTickets for help on using tickets.