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

6
  • Why have you used datetimepicker() twice ???? Commented Aug 25, 2014 at 13:42
  • i don't know if really, i used them for standart example, and this is working, but don't refresh Commented Aug 25, 2014 at 13:43
  • Try using once $('#datetimepicker').datetimepicker({value:aaa,step:10}); Commented Aug 25, 2014 at 13:44
  • yes) thanks it's working too)) but problem still present, the value not change Commented Aug 25, 2014 at 13:47
  • Can you create a js fiddle ?? Commented Aug 25, 2014 at 13:49

2 Answers 2

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>
Sign up to request clarification or add additional context in comments.

Comments

0

Try this :

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

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

12 Comments

try simple lile in example, clear field : $('#datetimepicker').datetimepicker("setDate", '{{ now_date|date:'Y-m-d H:i' }}'); or like this $('#datetimepicker').datetimepicker("setDate", new Date(2008,9,03) ); still clear field
When you click on your text box does it show up the date picker ??
What is the ID of your input field in which you are adding datetimepicker ??
sorry, i'm not understand
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.