I believe the attributes are populated by FormWidget._attributes but
not until the widget method is called. In your case I would create a
class like so:
class DatePickerFactory(object):
def __init__(self,dateformat="yy-mm-dd")
self.dateformat=dateformat
def widget(self,f,v,**attr):
inp = SQLFORM.widgets.string.widget(f,v, **attr)
scr = SCRIPT("jQuery('#%s').datepicker(dateFormat:'%s')" % (inp
['_id'],self.dateformat))
return DIV(inp,scr)
DateWidget = DatePickerFactory(dateformat="dd-mm-yyyy")
db.define_table('test',Field('posted',widget=DateWidget.widget))
There may be a better way though...
On Nov 3, 5:22 pm, Thadeus Burgess <[email protected]> wrote:
> I was looking at SQLFORM, and noticed that widgets do not actually get
> passed any attributes... at all.
>
> So why are they there? lol.
>
> elif hasattr(field, 'widget') and field.widget:
> inp = field.widget(field, default)
>
> Easily fixed to be
>
> elif hasattr(field, 'widget') and field.widget:
> inp = field.widget(field, default, **attributes)
>
> -Thadeus
>
> On Tue, Nov 3, 2009 at 5:04 PM, Thadeus Burgess <[email protected]>wrote:
>
> > Say I have a special value I want to pass to my widget. Like, date format.
> > Which could change depending on the page.
>
> > This is what I am trying to do.
>
> > # pseudocode.
> > def mywidget(f, v, **attr):
> > if attr.get("cancel", False):
> > return jQuery.Rating({cancel:true})
>
> > But I can't seem to figure out where that **attr dictionary comes from, its
> > not the SQLFORM, or the Field definitions?
>
> > #db.define_table("table", Field("hi", widget=mywidget, cancel=True)
> > #form = SQLFORM(db.table, cancel=True)
>
> > So is there a proper way of doing this?
>
> > -Thadeus
>
> > On Tue, Nov 3, 2009 at 4:32 PM, mr.freeze <[email protected]> wrote:
>
> >> That's where the 'cheesy' part comes in. This should really be done
> >> as a class with options passed in the constructor. As it is, you need
> >> to pass you attributes to the specific elements that will use them.
> >> For example in the datepicker widget, I override the class so the
> >> normal Calendar script doesn't affect it:
>
> >> inp = SQLFORM.widgets.string.widget(f,v,_class="jqdate", **attr)
>
> >> On Nov 3, 4:28 pm, Thadeus Burgess <[email protected]> wrote:
> >> > Freeze,
>
> >> > How would you pass variables to the **attr dict of the widgets?
>
> >> > -Thadeus
>
> >> > On Tue, Nov 3, 2009 at 4:06 PM, mr.freeze <[email protected]> wrote:
>
> >> > > I have a cheesy autocomplete widget here. It's no match for the
> >> > > facebook version but might help someone:
>
> >> > >http://www.web2pyslices.com/main/slices/take_slice/24
>
> >> > > On Nov 3, 11:24 am, Alex Fanjul <[email protected]> wrote:
> >> > > > I love this kind of widget!!! maybe your next challene would be the
> >> so
> >> > > > famous "facebook-autocomplete".
> >> > > > Nowdays in facebook there is also a new feature where you can
> >> appoint a
> >> > > > "friend" writting "@friend" as twitter did it, but with
> >> autocompleter...
>
> >> > > > By the way Mr. Freeze, I think we should talk with someone who
> >> proposed
> >> > > > and was working on a wrapper framework por jquery widgets...
> >> > > > I cant find the email.... She proposed us 3 options to choose for
> >> > > > implementation...
>
> >> > > > Alex F
>
> >> > > > El 03/11/2009 7:06, mr.freeze escribió:
>
> >> > > > > Nothing like a slice of web2py before bedtime :) I'm going widget
> >> > > > > crazy! Here's an in-place edit widget that presents your text as a
> >> > > > > SPAN until you double click then it changes into an input.
>
> >> > > > >http://www.web2pyslices.com/main/slices/take_slice/23
>
> >> > > > > On Nov 3, 12:01 am, mdipierro<[email protected]> wrote:
>
> >> > > > >> These slices taste excellent!
>
> >> > > > >> On Nov 2, 11:56 pm, "mr.freeze"<[email protected]> wrote:
>
> >> > > > >>> Thanks, I updated it to specify adding to the model or
> >> controller.
>
> >> > > > >>> On Nov 2, 11:33 pm, mdipierro<[email protected]> wrote:
>
> >> > > > >>>> Thank you Mr Freeze.
>
> >> > > > >>>> One comment. I do not think people should edit
> >> web2py_ajax.html.
>
> >> > > > >>>> response.files.append should go in plugin models or controller
> >> of
> >> > > the
> >> > > > >>>> plugin; or the<scrip...> should go directly in the views.
>
> >> > > > >>>> Massimo
>
> >> > > > >>>> On Nov 2, 10:48 pm, "mr.freeze"<[email protected]> wrote:
>
> >> > > > >>>>> Here are two ready to use widgets that employ the jQueryUI
> >> slider
> >> > > and
> >> > > > >>>>> datepicker:
>
> >> > > > >>>>> slider -http://www.web2pyslices.com/main/slices/take_slice/20
> >> > > > >>>>> datepicker -
> >>http://www.web2pyslices.com/main/slices/take_slice/22
>
> >> > > > >>>>> Have fun!
>
> >> > > > --
> >> > > > Alejandro Fanjul Fdez.
> >> > > > [email protected]
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py-users" 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/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---