Can't select day 8 and 9 in datepicker plugin for Symfony (sfFormExtraPlugin)
I am currently using the JQuery plugin Datepicker in my Symfony project with the sfFormExtraPlugin. Everything is working fine but there is a seems to be a strange bug in开发者_JAVA技巧 the plugin. If I select 8 or 9 in any month the day is not selected in the form. The month and year work correctly but the day is not selected. The plugin works correctly for all other days but not for those two days.
The date format that I use is day/month/year. Not sure if thats part of the problem.
Thanks!
Here is the code I use to initialize the widget:
$years = range(date('Y'), date('Y')-80);
$this->widgetSchema['fecha_nacimiento'] = new sfWidgetFormJQueryDate(array(
'image'=>'/images/calendario.jpg',
'culture' => 'es',
'date_widget' => new sfWidgetFormDate(array('format'=>'%day%/%month%/%year%',
'years' => array_combine($years, $years)))
)
);
I should also mention that other people have told me they had the same problem. It seems to be a problem with the plugin but am not sure.
Are you calling parseInt()
on something? Are you calling it like this:
var foo = parseInt(dateString);
or like this:
var foo = parseInt(dateString, 10);
?
It should be the second way. Your date string may be starting with "0", like "08" or "09". The parseInt
routine thinks you want it to read the numbers in base 8 (octal) because of that leading zero character. The second parameter (10) tells it explicitly that you want the string to be interpreted as a base 10 representation of a number.
The problem as Pointy points out is a parseInt() call. It is actually not one parseInt() call but three. As he also points out the datePicker works fine. The problem is inside the symfony plugin sfFormExtraPlugin. When it interfaces with the datePicker jQuery library there are three parseInt() calls that lack the necessary argument to indicate that they are decimal. The bug is actually quite easy to fix. In a typical installation you should find it in sfFormExtraPlugin/lib/widget/sfWidgetFormJQueryDate.class.php .
Then search for parseInt and the triplet is one of the first to appear. You only have to check that it follows the following structure: parseInt(arg, 10) (the important part is the ,10.
Thanks to Pointy for the inspiration.
Just to make sure none gets confused^^ it should look like this to work with day 8 and 9
function wfd_%s_update_linked(date)
{
jQuery("#%s").val(parseInt(date.substring(0, 4), 10));
jQuery("#%s").val(parseInt(date.substring(5, 7), 10));
jQuery("#%s").val(parseInt(date.substring(8), 10));
}
hope this helps
精彩评论