On Aug 4, 2006, at 2:12 PM, Renzo wrote:
>
> 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)
Just replace render for display:
${name1.display()}
However, If planning to build a form, *don't* place your field
widget's in the template like this, use a form or else you'll lose
all advantages of input validation. If you need to precisely layout
your fields in the template you can:
a) Edit the form's template, *my* preferred method:
class MyForm(Form):
template = """
<form xmlns:py="http://purl.org/kid/ns#" ...>
${display_field_for(item1)}<br /><hr />
${display_field_for(item2)}
</form>
"""
# the the template is somewhat simpplified, the form tag needs extra
attributes
b) Layout the fields in your page's template, good to work with
designers so they can edit the template file in their favorite editor:
-- controllers.py
@expose("mytpl")
def show_form(self)
return dict(myform=MyForm())
-- mytpl.kid --
<form ...>
${myform.display_field_for(item1)}
....
</form>
Sorry If this last piece of information wasn't what you were looking
for, I'm just guessing... ;)
HTH
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---