views:

56

answers:

2

Hi,

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 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.

A: 

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.

Pointy
I think this is a great idea. I have searched for that case but have been unable to find it. :(
Juan Besa
Well, it's happened to me and it's a pretty common problem. Do you have any of your own Javascript somewhere on the site? Where do you *interpret* the date values?
Pointy
Well like I said I don't have any javascript code. I just use the library and the way I use it is exactly what I put above. The problem has to be in the plugin or in Symfony. I was hoping someone would have had the same problem.
Juan Besa
Hi! Well you were right :) It was a ParseInt the problem was in the Symfony side with the plugin. If you add that you have to look for it in the following file to your answer I'd be happy to accept it. The file is: sfFormExtraPlugin/lib/widget/sfWidgetFormJQueryDate.class.phpThanks!
Juan Besa
A: 

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.

Juan Besa