TypeError: $.fn.datetimepicker.dates is undefined format: "dd/mm/yyyy"

TypeError: $.fn.datetimepicker.dates is undefined format: "dd/mm/yyyy"

webprophetswebprophets Posts: 18Questions: 5Answers: 0

Hi Allen.

I figure out the style sheet issue by adding bootstrap.css and bootstrap.js about previous question :
https://datatables.net/forums/discussion/comment/69152#Comment_69152

but some datatime picker icon gone. any idea ? I will keep checking whether I miss any file anyway.

But I got new error with format:

TypeError: $.fn.datetimepicker.dates is undefined
format: "dd/mm/yyyy"

my html code is:

                        {
                            "label": "Message create time",
                            "name": "time_add",
                            "type": "datetime",
                        }

my php code is:

                            Field::inst( 'time_add' )
        ->validator( 'Validate::dateFormat', array( 'empty'=>false, 'format'=>'M/d/Y H:i A' ) )
        ->getFormatter( 'Format::date_sql_to_format', 'd-M-Y H:i A' )
        ->setFormatter( 'Format::date_format_to_sql', 'M/d/Y H:i A' )

the expected text on datatime picker is like: 12/01/2014 11:30 AM

any suggestions?

Thank you very much

Answers

  • webprophetswebprophets Posts: 18Questions: 5Answers: 0

    I found another issue
    in my datatables , there are two data type with two datatime picker
    the first one is working, but for the second one, I can not get data on server end.

    how to modify the plugin code to make it work?

    Thanks

  • allanallan Posts: 63,676Questions: 1Answers: 10,497 Site admin

    Hi,

    Could we possibly continue this discussion in a single thread please? Hadn't realised that you'd already resolved the Bootstrap issue before replying to your previous thread. Thanks!

    but some datatime picker icon gone. any idea ?

    It looks like there is an error in the plug-in where it doesn't actually specify what icon should be shown! Where it has:

    `'<span class="input-group-addon"><span class="glyphicon"></span>'+

    Can you replace it with:

     '<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span>'+
    

    I'll update the site tomorrow morning.

    TypeError: $.fn.datetimepicker.dates is undefined

    I've just tried the URL you PM'ed me, but the server doesn't appear to be responding at the moment. I'll try again later on.

    Regards,
    Allan

  • webprophetswebprophets Posts: 18Questions: 5Answers: 0

    Hi Allen

    Sorry about multiple thread.
    I have solved icon miss issue by adding bootstrap font js css file , you may need mention these on bootstrap plugin document page as well:)

    the "TypeError: $.fn.datetimepicker.dates is undefined" seems that come from format function.

    After I change my php code to

                ->setFormatter(
                        function ( $val, $data, $opts ) {
    
                    return date('Y-m-d H:i:s', strtotime($val));
                }
                )
    

    it works

    But, for datetime picker, your validator function is not that quite right working

    if I code like this

              ->validator( 'Validate::dateFormat', array( 'empty'=>false, 'format'=>'m/d/Y h:i A' ) )
    

    it shows format doesn't match, but I check the http request , the format should be right, which means your validator function may not go through formate with min sec?

    I also try to customize validator code as below for testing

                ->validator(function ( $val, $data, $opts ) {
    
                    if (strlen( $val ) !=0) {
                        return true;
                    } else
                        return "time should not be null";
                })
    

    it works in some case.

    But I found a bug with two datetime picker on one table.

    Because datetime picker will auto fill up the text input, even you delete the text( leave it blank)( which is kind of no empty validation? I don know, but it helps)

    But if you delete one datetime picker text input(or try random funny input) , then delete (or try random funny input) for the second datetime picker, (When you input on the second one, the first datetime picker will auto fill the date back, it is fine, but......)

    the firebug will pop out "TypeError: conf._input.data(...).getDate(...) is null"
    and page is not working anymore.

    For testing this bug, you can try the html page I send you before. ( I will delete that page in couple days later, this bug is there , but not that important for us)

  • webprophetswebprophets Posts: 18Questions: 5Answers: 0

    One more question

    If I have two database , how to set up the config.php fire?or I can create two editor files with different name under Datatables extensions directory ?

  • allanallan Posts: 63,676Questions: 1Answers: 10,497 Site admin

    Hi,

    which means your validator function may not go through formate with min sec?

    It should do - however, I've just tried the page you sent me before, at it looks like the data for the date/time is being sent in a full Javascript format. For example:

    data[time] Sat Apr 25 2015 18:37:00 GMT+0100

    This is a function of moment.js's toString() method - it returns that format unless otherwise specified. You could modify the plug-in code to replace .toString() with .format(...) - or possibly update the PHP to validate the moment.js returned string. Possibly I should update the plug-in so it returns an ISO format which might be a bit more useful than the JS format. Your thoughts are welcome!

    But I found a bug with two datetime picker on one table.

    Thanks for letting me know about that. I'll take a look into it and try to see what the problem is.

    If I have two database , how to set up the config.php fire?or I can create two editor files with different name under Datatables extensions directory ?

    The DataTables.php file will automatically create a database connection based on the options in config.php. However, you can also use the Database class to create another database connection, in exactly the same way DataTables.php does, if you need. The documentation for that class is available here.

    Regards,
    Allan

  • allanallan Posts: 63,676Questions: 1Answers: 10,497 Site admin

    Update on the date / time picker. I've just made a change to the plug-in which will cause it to submit the value from the text box, rather than the Moment.js defined value (it was submitting a Javascript date / time string which wasn't much use...).

    Updated plug-in is available here: http://editor.datatables.net/plug-ins/field-type/editor.datetimepicker-2

    Regards,
    Allan

This discussion has been closed.