Renzo ha scritto:
> Hi, first of all sorry if this question has already been done, but i
> haven't found the answer..
> I've understood how it's possible to create a web form using widgets..
> for example:
>
> in controller:
> example_form = widgets.TableForm(
> fields=[widgets.TextField(name="test",label="Example"),
>
> widgets.TextField(name="test2",label="Example2"),for_widget,name1
> ],
> submit_text="Submit Me")
>
> in template:
> ${example_form(action="prova")}
>
> but it isn't so clear the way i've to follow to insert only a widgets,
> without a form.
> If i write:
> in controller:
> name1 = widgets.TextField("boh",validator=validators.NotEmpty())
> and in template:
> ${name1}
> looking at the web page, the result is:
> TextField(name='boh', convert=True, field_class='textfield', attrs={},
> css_classes=[]).
>
> Instead, if i write in template:
> ${name1.render()}
> the HTML result is:
> <INPUT ID="boh" TYPE="text" CLASS="textfield requiredfield"
> NAME="boh">
> that isn't correct because it is escaped (in particular the first
> character).
>
> Could anyone suggest me the correct way i've to follow to use correctly
> the TG widgets?
> Thanks,
> Renzo (Italy)
You should use:
name1.display()
or
name1()
(since a widget object is a callable linked to the display method)
you use the render method *only* outside of kid templates since it
dumps a plain string while display() dumps an elementtree structure.
If you're interested in using a custom layouted form inside your
template you can still use the original form in this way:
class MyFields(WidgetsList):
name = TextField()
comment = TextArea()
form = TableForm(fields=MyFields())
in your template (supposing you've passed the form variable to it) you
can do things like:
${form.display_field_for('name')}
${form.display_field_for('comment')}
Hope this helps.
Ciao
Michele
PS
Ti stavo rispondendo in TG-it ma ho visto lo stesso messaggio qui... ;-)
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---