0

I'm need your helps. I used jquery to create datetime picker, and them work fine, but one problem : When i set value to datetimepicker they set time load the page, when i'm try refresh the value of variable the jquery was crashed. Help please :

There is my code (failed) :

<script type="text/javascript">
var aaa = '{{ now_date|date:'Y-m-d H:i' }}'
$('#datetimepicker').datetimepicker()
        .datetimepicker({value:aaa,step:10});
</script>

P.S. : '{{ now_date|date:'Y-m-d H:i' }}' this is django now time

2 Answers2

1

Since you din't link a reference for jquery datetimepicker(), I assume you're talking about this: http://xdsoft.net/jqplugins/datetimepicker/

In order to accomplish your task, you have to:

  1. be sure that your timepicker starts after document loading using document.ready
  2. you're calling datetimepicker() on $('#datetimepicker'), then you're calling it again on an already jquery/datepicker object, with new parameters. I don't know if it may cause initialization problems, but i can assure you that it's useless.
  3. if you want to change datepicker value on the fly, you have to use it's own method like in this example: http://xdsoft.net/jqplugins/datetimepicker/#runtime_options

here's the code:

<script type="text/javascript">       
    $(document).ready(function(){
        $('#datetimepicker').datetimepicker({
            value : {{ now_date|date:'Y-m-d H:i' }},
            step : 10
        });
    });
    //below, an example of data variable refresh
    $('#datetimepicker').setOptions({value : {{ now_date|date:'Y-m-d H:i' }} });
</script>
pastorello
  • 922
  • 9
  • 22
0

Try this :

$(document).ready(function(){
    $('#datetimepicker').datetimepicker("setDate", aaa);
}

Try this, if this works then try adding other stuffs.

Yunus Aslam
  • 2,391
  • 4
  • 24
  • 37