Note that there are some explanatory texts on larger screens.

plurals
  1. POGet datepicker defaultdate from string/django object
    text
    copied!<p>I am a total (like no-experience-whatsoever) noob in jquery and Javascript, and what I would like to do is the following:</p> <p>I pass an article-object to my template that has date-information stored in it. I can access and display that information with <code>{{ article.pubdate }}</code>. Is it possible to set the <code>defaultDate</code> option of datepicker to the article date?<br> How would I go about that?</p> <p>Thanks for any pointers! </p> <p><strong>Update</strong>: Some more information about <code>{{ article.pubdate }}</code>:<br> It is a datetime object. The display format of the string can be edited, so <code>{{ article.pubdate|date:"Y-m-d"}}</code> gives a date like 2013-07-27.</p> <p><strong>Update 2</strong>: I display the article date on the page like this:</p> <pre><code>&lt;div id="article-pubdate"&gt; {{ article.pubdate|date:"Y-m-d" }} &lt;/div&gt; </code></pre> <p>This gives me <code>2013-07-27</code> as a string displayed on the page. After reading around I tried the following approach to get that string into datepicker like so: </p> <pre><code>&lt;script&gt; $(function () { var a = $("#article-pubdate").text(); var the_date = $.datepicker.parseDate("yy-mm-dd", a); $(".datepicker input").datepicker({ dateFormat: "yy-mm-dd", changeMonth: true, changeYear: true, yearRange: '1990:2013', defaultDate: the_date, }); }); &lt;/script&gt; </code></pre> <p>But this doesn't work, why?</p> <p><strong>Update 2</strong>: If I set <code>defaultDate</code> like so:</p> <pre><code>&lt;script&gt; $(function() { $( ".datepicker input" ).datepicker({ dateFormat: "yy-mm-dd", changeMonth: true, changeYear: true, yearRange:'1990:2013', defaultDate:"2001-01-01" }); }); &lt;/script&gt; </code></pre> <p>it works absolutely fine. Is there any way to pass the date info directly into datepicker?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload