formify ?

5 views
Skip to first unread message

AchipA

unread,
Apr 29, 2009, 7:35:42 AM4/29/09
to web2py Web Framework
I've been customizing some forms that needed to be editable by a
designer - we ended up having something I would call 'formify', at
least for the time of the development cycle. What's the idea here you
ask ? Imagine the following:

form=FORM(SELECT(...), INPUT(..), INPUT(...))

Now, this all nice but the layout either needs to be danced around
with css funk (can get messy if the field ordering needs to change,
etc) or with addressing form list elements from python in the view
(even worse).

However, what if we could say to our friendly designer - make the form
look whatever you want it to look, as long as you keep the specified
identifiers for the form fields. Then, we skip {{=form}} since it's
already there in html, and at the end of the view, we hop in with

{{=formify(form)}}

which will generate JS code that actually replaces/rewrites the
elements in the form with the ones in the 'form' var (based on their
id/names) while keeping the original (designer specified) attributes
of the elements.

Well, it took almost as much to write this post as to code my stopgap
solution (I'm not posting it here as it's very implementation
specific), but still, I'm curious about your thoughts about making
form design easier - this solution or other.

PS. And yes, this is backwards compatible :)

desfrenes

unread,
Apr 29, 2009, 12:38:00 PM4/29/09
to web2py Web Framework
sort of a form elements decorator... this has already been discussed
here, I'm sure Massimo wouldn't mind to include a nice solution to
this issue if someone has it. I too think there should be a way to
customize form markup. It has already been suggested that form can be
used for validation and its values can be used in a view with helpers
to create custom markup.

AchipA

unread,
Apr 29, 2009, 6:14:59 PM4/29/09
to web2py Web Framework
> customize form markup. It has already been suggested that form can be
> used for validation and its values can be used in a view with helpers
> to create custom markup.

Yes, that would be "addressing form list elements from python". Mighty
ugly IMHO when you take into account all you need to do to fill
default states (think selects, checkboxes, etc). The suggested formify
approach is an improvement in the sense that it does not interfere
with and clutter up the design elements of the form (making it more in
the spirit of a view), the flip side being that it does not work
without javascript.
Reply all
Reply to author
Forward
0 new messages