Nice Joe! Thanks for the recipe...

Until now I was creating custom widget for that, but this seems simpler,
because I was getting in trouble sometimes with custom widget when I was
requiring to alter a widget or set a differents widget, since I was getting
placeholder from a dabase dictionnary that I create for every fields in
every table. So, if I had to set a widget in the code I have to customize a
new placeholder attribute or pass placeholder as kargs...

Thanks

Richard


On Thu, Aug 8, 2013 at 2: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.


Reply via email to