Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #523 (closed enhancement: fixed)

Opened 13 years ago

Last modified 13 years ago

Forms, one step further

Reported by: michele Owned by: anonymous
Priority: normal Milestone: 0.9
Component: TG Widgets Version:
Severity: normal Keywords:
Cc:

Description

I'm going to attach a small patch and an example project that implements some of the ideas behind Django formfields and manipulator [1].

The approach I've taken let's you re-use your already defined form widget to easily customize it's appearance inside your destination template (not the widget template) and at the same time it keeps the controllers code intact.

This is quite useful (IMHO) if you want to use widgets to manage forms (they are very convenient and easy) but at the same time you still want a complete final template because you want to feed it to a designer, or you need fine control over the final output with a more complex layout (for example only some fields on the same row), or again you don't need a reusable style but just use widgets because you like them.

Basically I added some methods to the Form widget that you can use to retrieve a field widget instance that you can then use as every other widget (passing any argument you want to the display method, or use the render one).

For example, imagine a form widget definition like this one:

class Fields(WidgetsDeclaration):
    name = TextField(validator=validators.String())
    age = TextField(validator=validators.Int())

form = Form(fields=Fields(), submit_text="Save")

you will be able in your template to do something like this:

<p py:content="form.field_for('name').display(value='Michele')">Name goes here</p>

This is a nice addition IMO, easy to use and that adds a great degree of flexibility to the widgets framework.

What do you think? I'm open to any suggestion.

Personally I like this very much. :-)

[1]  http://www.djangoproject.com/documentation/forms/

Attachments

forms.patch Download (1014 bytes) - added by michele 13 years ago.
The patch, really small as you can see
NewWidgets.tar.gz Download (7.2 KB) - added by michele 13 years ago.
The example project, take a look at welcome.kid

Change History

Changed 13 years ago by michele

The patch, really small as you can see

Changed 13 years ago by michele

The example project, take a look at welcome.kid

comment:1 Changed 13 years ago by kevin

  • Status changed from new to closed
  • Resolution set to fixed
  • Milestone set to 0.9

I think the original "source" generation idea is ultimately the way to go for full customization, and template replacement is generally quite powerful. But, this is so easy it's hard to resist :)

committed in [677]

I am curious about the name "has_errors" when it does actually return the errors, and the getter is even called _get_errors

comment:2 Changed 13 years ago by michele

Damn, you are fast to commit! :-)

Please change has_errors to errors, I've got the same thinking as you. :-)

Note: See TracTickets for help on using tickets.