Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery Datepicker, select multiple dates and mark them via css at selection time, permanently
    primarykey
    data
    text
    <p>so I have spent a day developing and reading (teh other way around) to enable my jQuery datepicker to select and highlight mutliple dates.</p> <p>For this I have managed to write the selected dates to an array which is visualized in a simple textfield. </p> <p>What I could not manage is to permanently modify the look of the selected date in the datepicker.</p> <p>I have implemented the "beforeShowDay:" option, which is working properly uppon loading the datepicker, but of course is not called directly on selecting a date. For this I guessed, I would need to refresh the view "onSelect", but the refresh is not working properly. Right now, I have some small methods for handling the datearray. </p> <p>Uppon adding or removing a date, I am trying to refresh the datepicker.</p> <p>Uppon selecting a date, I am either adding it to, or remove it from the dates-array. Also, onSelect, I am matching the selected day and try to addClass(). </p> <p>But once again, I think I missed something all the way round, as it is not shown in my datepicker.</p> <p>Here's my code for now:</p> <pre><code>var dates = new Array(); function addDate(date) { if (jQuery.inArray(date, dates) &lt; 0 &amp;&amp; date) { dates.push(date); } } function removeDate(index) { dates.splice(index, 1); } // Adds a date if we don't have it yet, else remove it and update the dates // textfield function addOrRemoveDate(date) { var index = jQuery.inArray(date, dates); if (index &gt;= 0) { removeDate(index); updateDatesField(dates); } else { addDate(date); updateDatesField(dates); } jQuery(calContainer).datepicker("refresh"); } var calContainer = document.getElementById("calendar-container"); jQuery(calContainer).datepicker({ minDate : new Date(), dateFormat : "@", onSelect : function(dateText, inst) { addOrRemoveDate(dateText); jQuery(".ui-datepicker-calendar tbody tr td a").each(function() { if (jQuery(this).text() == inst.selectedDay) { jQuery(this).addClass("ui-state-highlight"); jQuery(this).parent().addClass("selected"); } }); // addTimeSelectorColumns(dates); }, beforeShowDay : function(_date) { var gotDate = -1; for ( var index = 0; index &lt; dates.length; index++) { if (_date.getTime() == dates[index]) { gotDate = 1; } else { gotDate = -1; } } if (gotDate &gt;= 0) { return [ true, "ui-datepicker-today", "Event Name" ]; } return [ true, "" ]; } }); function updateDatesField(dates) { if (dates.length &gt; 0) { var tmpDatesStrArr = new Array(); var dateString = ""; var datesField = document.getElementById("dates"); for ( var index = 0; index &lt; dates.length; index++) { var dateNum = dates[index]; var tmpDate = new Date(); tmpDate.setTime(dateNum); dateString = tmpDate.getDate() + "." + tmpDate.getMonth() + "." + tmpDate.getFullYear(); tmpDatesStrArr.push(dateString); } jQuery(datesField).val(tmpDatesStrArr); } } </code></pre> <p>(I am still a beginner in Javascript/jQuery, so any help or hints towards my coding are welcome, btw...)</p>
    singulars
    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.
    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