Javascript event onchange with Calendar

886 views
Skip to first unread message

José Luis Redrejo

unread,
Nov 5, 2013, 12:51:53 PM11/5/13
to web...@googlegroups.com
Hi,
I'm having problems with the Calendar used for date fields in an SQLFORM.
In the web page, the javascript onchange does never happen (tested
with Firefox and Google chrome). Other events like click or focusout
works correctly, and other fields with other text input widgets work
correctly too.

Is there any way to handle when the user changes the date after
clicking on a calendar day?

Thanks
José L.

Diogo Munaro

unread,
Nov 5, 2013, 1:08:03 PM11/5/13
to web...@googlegroups.com

Hi josé, you tried handle onchange with jquery on function? Phehaps some js after declared is changing you handle. So, try:

$(item).on("change", function(){});

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
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+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

José Luis Redrejo

unread,
Nov 5, 2013, 1:19:17 PM11/5/13
to web...@googlegroups.com
2013/11/5 Diogo Munaro <diogo....@gmail.com>:
> Hi josé, you tried handle onchange with jquery on function? Phehaps some js
> after declared is changing you handle. So, try:
>
> $(item).on("change", function(){});
>


Yes, and it doesn't work. In fact this is part of my code:

jQuery("#CabeceraEntrada_Fecha").change(function() {
set_parametros('fecha',jQuery(this));
});

jQuery("#CabeceraEntrada_tipoProcedencia").change(function() {
set_parametros('procedencia',jQuery(this));
});

jQuery('#CabeceraEntrada_Codigo').change(function(){
set_parametros('codigo',jQuery(this));
});

#CabeceraEntrada_Codigo is a normal text input (integer datafield),
#CabeceraEntrada_tipoProcedencia is a select (IS_IN_SET datafield
requirement) and #CabeceraEntrada_Fecha is a text input with calendar
(date datafield).
With the same code, they all execute set_parametros function,
excepting #CabeceraEntrada_Fecha

Diogo Munaro

unread,
Nov 5, 2013, 8:35:22 PM11/5/13
to web...@googlegroups.com

No jose, try use .on instead of .change as the example

José Luis Redrejo

unread,
Nov 6, 2013, 1:36:30 AM11/6/13
to web...@googlegroups.com
2013/11/6 Diogo Munaro <diogo....@gmail.com>:
> No jose, try use .on instead of .change as the example
>

I tried it too, without success.

Derek

unread,
Nov 6, 2013, 1:03:12 PM11/6/13
to web...@googlegroups.com
You can't do that, because of recent changes in web2py.js source code by niphlod. The 'calendar' js does have a method that would work after the date was changed.
(see line 182 - he specifically sets the 'onChange' of the input.datetime)

To do that, you need to modify the web2py.js file, line 188 which sets up the calendar - you have to add your callback. In the setup you need to define what 'onUpdate' does.
See the documentation to the calendar widget used here:

José Luis Redrejo

unread,
Nov 6, 2013, 1:05:47 PM11/6/13
to web...@googlegroups.com
Derek, thank you for the info. I could not guess it was so
complicated. I don't like to modify files that are part of the
framework as they will change with future updates.
Don't you think this is a bug that should be fixed in web2py?

2013/11/6 Derek <sp1...@gmail.com>:

Derek

unread,
Nov 6, 2013, 1:20:33 PM11/6/13
to web...@googlegroups.com
Well, I can't say if it's a bug or not, Niphlod would be able to determine that. He made the change to fix something. I can't find an issue that corresponds with this change though.

The only thing I could suggest then is to use the calendar setup yourself, and instead of adding the web2py.js automatically in layout.html, remove that and load it yourself in your view before you load your javascript to set the calendar up.

Niphlod

unread,
Nov 6, 2013, 2:35:16 PM11/6/13
to web...@googlegroups.com
nothing has changed event-wise from the "old" web2py.js to the new one (included in web2py >= 2.6.0).
"Before web2py 2.6.0" the calendar was hooked as soon as discovered into the page (even if the user didn't click on the field), now instead it is initialized as soon as a user clicks on it.
This enabled the calendar widget to work even if the field is initially hidden (a common recurrence in "tabbed-styled" interfaces and on "mobiles-friendly" templates).

The docs about the events on the widget are here http://www.dynarch.com/jscal/#sec29

@all: BTW, if anyone can find a js calendar widget that:
- works with dates
- works with datetimes
- works with times
- understands strftime formatting for dates (needed to "translate" the form value according to the current translation of the page)
- is backward compatible
- doesn't need any additional huge js library
please free to post here or in the group.
The calendar.js shipped with web2py is starting to show its age and its "unmaintenance" ;-)

Reply all
Reply to author
Forward
0 new messages