Adding a Widget to a simple FORM() input()

41 views
Skip to first unread message

Lennon

unread,
Apr 5, 2011, 5:58:29 PM4/5/11
to web2py-users
I'm trying to add the jquery UI datepicker from this web2py slice:
http://web2pyslices.com/main/slices/take_slice/22

It works well with SQLFORM, but I want to use it on a form I've
defined with the FORM() helper.

Is there a way to do this using a simple syntax similar to the
widget=date_widget syntax?

Do I have to somehow change the default way an input with a class of
"date" is rendered?

Do I just have to do a normal integration using css?

Thanks for any help you can give.

DenesL

unread,
Apr 5, 2011, 7:12:00 PM4/5/11
to web2py-users

Just add _class="date" to your INPUT field definition.

Lennon

unread,
Apr 5, 2011, 9:13:03 PM4/5/11
to web2py-users
I am aware of that method but I really don't like the default date and
datetime widget.

I want to use the one from that web2py slice.

DenesL

unread,
Apr 5, 2011, 10:35:44 PM4/5/11
to web2py-users

OK, now I understand.
I would modify web2py_ajax.html at the beginning to include:

response.files.append("http://ajax.googleapis.com/ajax/libs/jqueryui/
1.7.2/jquery-ui.js")

or a similar line, and then in the web2py_ajax_init function add:

jQuery('input.jqdate').datepicker({dateFormat:'yy-mm-dd'})

after that you can _class="jddate" your INPUT fields.

Lennon

unread,
Apr 6, 2011, 3:37:15 PM4/6/11
to web2py-users
That worked for me. Thank you.

I also needed a datetime picker as well and I was able to use this
one:

http://trentrichardson.com/examples/timepicker/js/jquery-ui-timepicker-addon.js

with the follow line:

jQuery('input.jqdatetime').datetimepicker();

In case that's helpful to anyone. It just works on top of the other
jquery date picker.
Reply all
Reply to author
Forward
0 new messages