This is a question better suited to the ToscaWidgets mailing list, so you
might want to ask there for a better answer.

To set the currently selected genre simply pass to the form display call a
value={} parameter that contains the key of the field and the value it
should be set to.

To filter the Genre you have multiple options, the one I prefer is usually
to override the prepare method of the form to perform such actions.
the prepare method is called right before displaying the widget, so you can
change there any property depending on the context.

I usually do something like:
    def prepare(self):
        set_child_value(self, 'entry_type', 'options', [1,2,3])
        super(MyCustomForm, self).prepare()

where set_child_value is a function that looks like:

def set_child_value(w, childname, property, value):
    if w.child:
        w = w.child
    for c in w.children:
        if c.key == childname:
            setattr(c, property, value)
            break

maybe one of the tw2 guys has a better solution for this.


On Thu, Jan 10, 2013 at 10:55 PM, Craig Small <[email protected]> wrote:

> I'm hoping the list can "bridge the gap" between my controller and
> widget.  I have two problems:
>   A drop-down custom widget with options from a database field that
>     is filtered from sometinhg in the url
>   The widget "remembers" the last chosen option
>
> So I have a widget much like
>
> https://turbogears-dev.readthedocs.org/en/workshop/cookbook/sprox.html#creating-custom-dropdown-data
> and it has ALL of the options from my table. By given the access of
>   http://localhost:8080/thing/42
> my controller grabs the 42 so it knows item_id=42, so far so good.
> My widget shows all genres, so far so good.
>
> But I want my widget to only show the options filtered by this item, so
> the database access would have filter(model.Genre.other_key == 42)
> appended to it.
>
> How do I get the item_id variable out of my controller into my widget?
>
> Second problem, I select a genre and hit submit, I want that widget to
> have the default of the one I selected instead of blank which is what it
> does now. Again the controller "sees" the selection but its a matter of
> letting the widget know.
>
>   - Craig
> --
> Craig Small VK2XLZ   http://enc.com.au/          csmall at : enc.com.au
> Debian GNU/Linux     http://www.debian.org/      csmall at : debian.org
> GPG fingerprint:     5D2F B320 B825 D939 04D2  0519 3938 F96B DF50 FEA5
>
> --
> 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.
>
>

-- 
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.

Reply via email to