Nice, post it in web2pyslices!!!

2013/8/8 Vinicius Assef <vinicius...@gmail.com>

> Excellent approach. :-)
>
> On Thu, Aug 8, 2013 at 3:11 PM, Joe  Barnhart <joe.barnh...@gmail.com>
> wrote:
> > So I'm a control-freak.  I mean that in a good way.  I discovered the
> beauty
> > of "placeholders" in forms and just thought "man, I really want that!"
>  But
> > where to hold the placeholder data?  And how do I get it to the SQLFORM
> > during form creation?
> >
> > At first I thought about adding YAV (yet another variable) to the Field
> > class.  But it's getting pretty crowded in there already, and mucking
> with
> > it means changes to the base, and the devs might object to a
> special-purpose
> > hack inserted into Field just to satisfy my whims.  So I thought I'd just
> > create my own formstyle function and use that.  But wait!  The formstyle
> > function has a defined signature now, and there is no place to insert
> > anything like a dictionary of placeholders indeded by field name.  Or is
> > there...
> >
> > I created my own formstyle function, but added a keyword parameter to the
> > end for the placeholders dict.  The signature looke like this:
> >
> >
> > def my_fieldstyle(form, fields, placeholders=None):
> >     ...blah...
> >
> >
> > Now, the code in SQLFORM still has no idea that these placeholders exist.
> > But I can "wrap" this function with either a "partial function" or a
> simple
> > lambda to provide my own dictionary just before the customized formstyle
> > function is handed off to SQLFORM for it's main job.  It looks like this:
> >
> >
> > my_placeholder_dict = {'field1': 'place1', 'field2', 'place2'...}
> > ...
> > styler = lambda form, fields: my_fieldstyle(form, fields,
> > placeholders=my_placeholder_dict)
> > ...
> > form = SQLFORM(... formstyle=styler ...)
> >
> >
> > That's all there is to it!  Now I can pass abundant information into the
> > SQLFORM created, info that the base form creation has no idea exists.  My
> > own custom formstyle class can interpret the extra information and add
> all
> > kinds of special features.  Just a few ideas:
> >
> > 1.  Provide "placehloders" for phone and date fields to show proper
> format
> >
> > 2.  Provide dictionary of "field sets" with "legends" and create a
> > structured form organized the way I want
> >
> > 3.  ... and many many more!
> >
> > Best of all, it only needs stupid Python tricks and doesn't much with the
> > underlying structure of web2py at all!  No nasty stares from the devs!
> > (Just kidding...)
> >
> > -- Joe
> >
> > --
> >
> > ---
> > You received this message because you are subscribed to the Google Groups
> > "web2py-users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to web2py+unsubscr...@googlegroups.com.
> > For more options, visit https://groups.google.com/groups/opt_out.
> >
> >
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to