Avoiding a Javascript error - FIXED IN V3.4

Post Reply
RWAP
Site Admin
Posts: 748
Joined: Fri Jan 08, 2010 2:23 am
Location: Stoke-on-Trent
Contact:

Avoiding a Javascript error - FIXED IN V3.4

Post by RWAP » Tue Oct 23, 2012 10:44 pm

I have come across the instance where a javascript error is being produced on the date passed to the datepicker.

The issue comes from (for example) the following javascript:

Code: Select all

$('input.datepicker').datepicker("setDate", new Date(2012,10,09,0,1,0,0));
This reports an issue that 09 is not a valid octal number.

This can be overcome by changing the code in class\Date.php

Find:

Code: Select all

    static public function javascriptFormated($d){
        $parts = preg_split("(/|-)", $d);
        return $parts[0].','.($parts[1]-1).','.$parts[2].',0,1,0,0';
    }
Change this to read:

Code: Select all

    static public function javascriptFormated($d){
        $parts = preg_split("(/|-)", $d);
        return ltrim($parts[0],'0').','.ltrim(($parts[1]-1),'0').','.ltrim($parts[2],'0').',0,1,0,0';
    }
This removes the leading zeros

RWAP
Site Admin
Posts: 748
Joined: Fri Jan 08, 2010 2:23 am
Location: Stoke-on-Trent
Contact:

Re: Avoiding a Javascript error

Post by RWAP » Thu Jan 03, 2013 2:38 pm

Oops - I introduced a new bug - the function should read:

Code: Select all

    static public function javascriptFormated($d){
        $parts = preg_split("(/|-)", $d);
        $month=ltrim(($parts[1]-1),'0');
        if ($month=='') $month=0;
        return ltrim($parts[0],'0').','.$month.','.ltrim($parts[2],'0').',0,1,0,0';
    }

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest