Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make days enabled in UI datepicker after month change?
    primarykey
    data
    text
    <blockquote> <p>Original question link: <a href="https://stackoverflow.com/questions/4171775/help-how-to-make-days-enabled-in-ui-datepicker-after-month-change">Help! How to make days enabled in UI datepicker after month change?</a></p> </blockquote> <p>First of all, The solution of Nick Craver is wonderful. But I got another problem:</p> <p>The Nick Craver's date source was came from the js variable <code>xml</code>, but my date source comes from a xml file. So I got the same date result but the datepicker didn't display right in my way.</p> <p>Nick Craver's code: </p> <pre><code>var xml = '&lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;users&gt;&lt;user id="126"&gt;&lt;name&gt;john&lt;/name&gt;&lt;watchHistory&gt;&lt;whMonthRecords month="2010-10"&gt;&lt;whDateList month="2010-10"&gt;&lt;date&gt;01&lt;/date&gt;&lt;date&gt;05&lt;/date&gt;&lt;date&gt;21&lt;/date&gt;&lt;/whDateList&gt;&lt;/whMonthRecords&gt;&lt;whMonthRecords month="2010-11"&gt;&lt;whDateList month="2010-11"&gt;&lt;date&gt;01&lt;/date&gt;&lt;date&gt;05&lt;/date&gt;&lt;date&gt;06&lt;/date&gt;&lt;date&gt;07&lt;/date&gt;&lt;date&gt;08&lt;/date&gt;&lt;date&gt;09&lt;/date&gt;&lt;date&gt;12&lt;/date&gt;&lt;date&gt;13&lt;/date&gt;&lt;date&gt;14&lt;/date&gt;&lt;date&gt;16&lt;/date&gt;&lt;date&gt;18&lt;/date&gt;&lt;date&gt;19&lt;/date&gt;&lt;date&gt;21&lt;/date&gt;&lt;date&gt;22&lt;/date&gt;&lt;date&gt;23&lt;/date&gt;&lt;date&gt;24&lt;/date&gt;&lt;date&gt;25&lt;/date&gt;&lt;date&gt;26&lt;/date&gt;&lt;date&gt;29&lt;/date&gt;&lt;/whDateList&gt;&lt;/whMonthRecords&gt;&lt;/watchHistory&gt;&lt;/user&gt;&lt;/users&gt;'; var daysWithRecords = []; function getDays(year,month){ initDaysArray( $(xml) , year , month ); } </code></pre> <p>and my want it to be: [didn't work]</p> <pre><code>var daysWithRecords = []; function getDays(year,month){ $.ajax({ type: "GET", url: "users.xml", dataType: "xml", success:function(data){ initDaysArray($(data) , year , month ); } }); </code></pre> <p>function <code>initDaysArray()</code>:</p> <pre><code>function initDaysArray( $xml , year , month ){ var dateToFind = year+'-'+month; daysWithRecords = $xml.find('user[id="126"] whDateList[month="'+dateToFind+'"] date').map(function() { return dateToFind +"-"+ $(this).text(); }).get(); for(i = 0; i &lt; daysWithRecords.length; i++){ console.log(daysWithRecords[i]); } } </code></pre> <p>I test via Firebug. It seems the function being called in the order of:</p> <pre><code>first call: getDays() // being called from onChangeMonthYear second call: checkAvailability() // being called from beforeShowDay third call: ajax inside getDays() // being called inside getDays() final call: initDaysArray() // being called inside ajax success of getDays() </code></pre> <p>so, the <code>initDaysArray[]</code> <strong>always empty</strong> inside <code>checkAvailability()</code></p> <p><strong>[My solution]</strong></p> <p>I found this way to figure it out:</p> <p>using <code>datepicker's method "refresh"</code> to redraw the datepicker after ajax read the xml file</p> <pre><code>function getDays(year,month,inst){ $.ajax({ type: "GET", url: "users.xml", dataType: "xml", cache: false, success:function(data){ console.log('reading xml file success!'); initDaysArray( $(data) , year , month ); //inst.id get the div which attached with datepicker and redraw $('#'+inst.id).datepicker('refresh'); console.log(inst.id); } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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