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 #1374 (closed defect: worksforme)

Opened 11 years ago

Last modified 11 years ago

widgets.SingleSelectField()

Reported by: awalker Owned by: alberto
Priority: high Milestone: 1.0.2
Component: ToscaWidgets Version: 1.0.1
Severity: normal Keywords: SingleSelectField widgets form elements
Cc:

Description

prov_list = [("1", "British Columbia"), ("2", "Alberta"), ("3", "Saskatchewan"), ("4", "Manitoba"), ("5", "Ontario")]
province = widgets.SingleSelectField(options=prov_list, label="Province", default="5") 

Does not preselect option 5, Ontario.

Change History

comment:1 follow-up: ↓ 2 Changed 11 years ago by alberto

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

Hmm, I've tried to reproduce and found no problem...

>>> from turbogears import widgets
>>> prov_list = [("1", "British Columbia"), ("2", "Alberta"), ("3", "Saskatchewan"), ("4", "Manitoba"), ("5", "Ontario")]
>>> province = widgets.SingleSelectField(options=prov_list, label="Province", default="5")
>>> print province.render()
<select class="singleselectfield" name="widget" id="widget">
            <option value="1">British Columbia</option><option value="2">Alberta</option><option value="3">Saskatchewan</option><option value="4">Manitoba</option><option selected value="5">Ontario</option>
    </select>

Looks selected to me, maybe I'm missing something? Please reopen if so...

Alberto

comment:2 in reply to: ↑ 1 ; follow-up: ↓ 3 Changed 11 years ago by kvaml

  • Status changed from closed to reopened
  • Resolution worksforme deleted

Replying to alberto:

Hmm, I've tried to reproduce and found no problem...

>>> from turbogears import widgets
>>> prov_list = [("1", "British Columbia"), ("2", "Alberta"), ("3", "Saskatchewan"), ("4", "Manitoba"), ("5", "Ontario")]
>>> province = widgets.SingleSelectField(options=prov_list, label="Province", default="5")
>>> print province.render()
<select class="singleselectfield" name="widget" id="widget">
            <option value="1">British Columbia</option><option value="2">Alberta</option><option value="3">Saskatchewan</option><option value="4">Manitoba</option><option selected value="5">Ontario</option>
    </select>

Looks selected to me, maybe I'm missing something? Please reopen if so...

Alberto

Try getting xhtml out!

print province.render('xhtml')

<select class="singleselectfield" name="widget" id="widget">

<option value="1">British Columbia</option><option value="2">Alberta</option><option value="3">Saskatchewan</option><option value="4">Manitoba</option><option value="5">Ontario</option>

</select>

comment:3 in reply to: ↑ 2 Changed 11 years ago by kvaml

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

Replying to kvaml:

Replying to alberto:

Hmm, I've tried to reproduce and found no problem...

>>> from turbogears import widgets
>>> prov_list = [("1", "British Columbia"), ("2", "Alberta"), ("3", "Saskatchewan"), ("4", "Manitoba"), ("5", "Ontario")]
>>> province = widgets.SingleSelectField(options=prov_list, label="Province", default="5")
>>> print province.render()
<select class="singleselectfield" name="widget" id="widget">
            <option value="1">British Columbia</option><option value="2">Alberta</option><option value="3">Saskatchewan</option><option value="4">Manitoba</option><option selected value="5">Ontario</option>
    </select>

Looks selected to me, maybe I'm missing something? Please reopen if so...

Alberto

Try getting xhtml out!

That should have been format='xhtml'

And then it does output selected

print province.render(format='xhtml')

<select class="singleselectfield" name="widget" id="widget">

<option value="1">British Columbia</option><option value="2">Alberta</option><option value="3">Saskatchewan</option><option value="4">Manitoba</option><option selected="selected" value="5">Ontario</option>

</select>

Sorry about creating the extra noise.

comment:4 Changed 11 years ago by kvaml

I have been having a similar with selected defaults not appearing in the html. I finally tracked it down to an error with validators in formencode. The error is not reported by turbogears, but it interferes with rendering the selected attribute.

Note: See TracTickets for help on using tickets.