Provide default value to a form widget

View: New views
3 Messages — Rating Filter:   Alert me  

Provide default value to a form widget

by mettwoch :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi,

I've seen the new TG 1.05 feature to provide a function to the default
value of a widget. Please help me I'm confused now and can't see how
to use that. Let's say that I've a controller method exposed and that
gets an argument called "code". How can I provide the value of that
argument as a default to a TextField widget contained in a TableForm
exposed by that controller method.

    SomeFormFields(WidgetsList):
        code = TextField()

    someForm = TableForm(fields = SomeFormFields())

    @expose(template = "someForm")
    def someMethod(self, code):
        ...
        return dict(someForm = someForm)

Thanks for any hint

Marc
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to turbogears@...
To unsubscribe from this group, send email to turbogears-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Provide default value to a form widget

by Florent Aide :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Thu, Jul 3, 2008 at 4:05 PM, mettwoch <mettwoch@...> wrote:

>
> Hi,
>
> I've seen the new TG 1.05 feature to provide a function to the default
> value of a widget. Please help me I'm confused now and can't see how
> to use that. Let's say that I've a controller method exposed and that
> gets an argument called "code". How can I provide the value of that
> argument as a default to a TextField widget contained in a TableForm
> exposed by that controller method.
>
>    SomeFormFields(WidgetsList):
>        code = TextField()
>
>    someForm = TableForm(fields = SomeFormFields())
>
>    @expose(template = "someForm")
>    def someMethod(self, code):
>        ...
>        return dict(someForm = someForm)
>
> Thanks for any hint

In your controller:

return dict(someForm=someForm, value=dict(code=code))

In your kid template or whatever (just adapte to your case):

<span py:content="someForm.display(value=value)">content that will be
replaced</span>

Florent.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to turbogears@...
To unsubscribe from this group, send email to turbogears-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Provide default value to a form widget

by mettwoch :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Oooh, of course. I'm tired I think ;-)

Thanks

On Jul 3, 4:20 pm, "Florent Aide" <florent.a...@...> wrote:

> On Thu, Jul 3, 2008 at 4:05 PM, mettwoch <mettw...@...> wrote:
>
> > Hi,
>
> > I've seen the new TG 1.05 feature to provide a function to the default
> > value of a widget. Please help me I'm confused now and can't see how
> > to use that. Let's say that I've a controller method exposed and that
> > gets an argument called "code". How can I provide the value of that
> > argument as a default to a TextField widget contained in a TableForm
> > exposed by that controller method.
>
> >    SomeFormFields(WidgetsList):
> >        code = TextField()
>
> >    someForm = TableForm(fields = SomeFormFields())
>
> >    @expose(template = "someForm")
> >    def someMethod(self, code):
> >        ...
> >        return dict(someForm = someForm)
>
> > Thanks for any hint
>
> In your controller:
>
> return dict(someForm=someForm, value=dict(code=code))
>
> In your kid template or whatever (just adapte to your case):
>
> <span py:content="someForm.display(value=value)">content that will be
> replaced</span>
>
> Florent.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to turbogears@...
To unsubscribe from this group, send email to turbogears-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---