Adam Jones schrieb:
>
> Matt Wilson wrote:
>> I have a database table that will be empty now and later will have rows
>> in it.
>>
>> Once I have rows, I want to create a SingleSelectWidget that allows
>> users to choose rows.
>>
>> In the mean time, if the database table is empty, I don't want to
>> display the select form in my template.
>>
>> I wrote this goofy function that either returns a select widget, or
>> None, depending on if the underlying table is empty:
>
> I see two options here, one relatively easy, one slightly harder.
>
> The easy one is to make an empty widget that returns nothing when its
> display method is called, return that instead of None, and clean up
> your template to just a ${carriers.display()} call.
>
> The harder one would be to alter SingleSelectField so that it does not
> emit html if there are no items in the list.
Don't think that would be too hard. Do something like this (out of my
head, thus untested):
class HidingSingleSelectField(SingleSelectField):
template="path.to.template"
Then, copy the standard to "path.to.template" - and alter it like this:
<select xmlns:py="http://purl.org/kid/ns#"
py:if="len(options)"
name="${name}"
class="${field_class}"
id="${field_id}"
py:attrs="attrs"
>
<optgroup py:for="group, options in grouped_options"
label="${group}"
py:strip="not group"
>
<option py:for="value, desc, attrs in options"
value="${value}"
py:attrs="attrs"
py:content="desc"
/>
</optgroup>
</select>
That should be it.
Diez
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---