14

I want to disable a date range in joomla calendar. Only the remaining days can be select. I have no idea how to do it. Plz help.

e.g. If I say 2012-2-20 to 2012-3-20 then only days in this range can be select all other has to be disable(or can not select).

Joomla Calendar Doc http://docs.joomla.org/API16:JHtml/calendar

Sara
  • 14,098
  • 13
  • 34
  • 50
  • 3
    This ain't very easy at all, but [see this](http://technologymisc.wordpress.com/2011/08/17/joomla-hide-past-days-from-calendar-control/) for a bit of related code. – Matteus Hemström Feb 20 '12 at 14:57
  • 2
    What are you trying to do specifically? You'll probably be better off writing something custom for this. – Brent Friar Feb 20 '12 at 20:44
  • 1
    Ok, where exactly do you want to accomplish this? Is this in a custom component or extension? On the front end or in the admin back end? – Brent Friar Feb 21 '12 at 08:10
  • @BrentFriar In a custom component @ the backend. – Sara Feb 29 '12 at 03:17
  • This might be worth checking out: http://stackoverflow.com/questions/1890418/datepicker-for-web-page-that-can-allow-only-specific-dates-to-be-clicked – Zeleres May 12 '12 at 04:14

5 Answers5

1

Set minDate and maxDate for your date limit, i.e.

$("#start_date").datepicker({
    dateFormat:'yy-mm-dd',
    showOn: 'button',
    buttonImageOnly: true,
    minDate: newmindate ,
    maxDate: newmaxdate 
});

Set variable newmindate and newmaxdate.

Kijewski
  • 25,517
  • 12
  • 101
  • 143
Rakesh
  • 756
  • 8
  • 10
0

What I would do is add a little snippet of code in Javascript where any time you have an event on blur on that input you retrieve the value, check if it is > 2012-2-10 && < 2012-3-10, and if not clear the value of that input.

Perception
  • 79,279
  • 19
  • 185
  • 195
Yazo
  • 137
  • 2
  • 12
0

I ran into a similar problem with several Joomla sites that I administer. I was already using jQuery, so I decided to go with JQuery UI Datepicker which has an easy-to-use min/max date feature. If you're already using these libraries, or if you're willing to 1) add them and 2) potentially mess up your design unity, I would recommend it.

Ben Jacobs
  • 2,526
  • 4
  • 24
  • 34
  • Yes I tried spending lot of time with Joomla calender but failed. So I had to use JQuery UI Datepicker to do it but still thinking and hoping to do the same thing using joomla calender. – Sara Jun 26 '12 at 16:21
  • @Sara let me know if you do... I too would like a native solution on my Joomla sites. – Ben Jacobs Jun 26 '12 at 16:30
0
<div>
    <input name="StartDate" id="StartDate" type="text" readOnly="readonly" data-val-required="The From field is required." data-val="true" jQuery15106987620498322786="53"/>
    <input name="EndDate" id="EndDate" type="text" readOnly="readonly" data-val-required="The To field is required." data-val="true" jQuery15106987620498322786="54"/>
</div>

$(function () {
    var dates = $("#StartDate, #EndDate").datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        changeYear: true,
        numberOfMonths: 1,
        minDate:0,
        dateFormat: 'dd/mm/yy',
        onSelect: function (selectedDate) {
            var option = this.id == "StartDate" ? "minDate" : "maxDate",
                    instance = $(this).data("datepicker"),
                    date = $.datepicker.parseDate(
                        instance.settings.dateFormat ||
                        $.datepicker._defaults.dateFormat,
                        selectedDate, instance.settings);
            dates.not(this).datepicker("option", option, date);
        }

    });
});
lasitha edirisooriya
  • 793
  • 2
  • 13
  • 15
0

3 years after your question and the calendar field in Joomla still can't do this. However, you can set a minimum year and a maximum year (but not a minimum month and a maximum month) by just editing the file media/system/js/calendar.js and changing the values of this.minYear and this.maxYear to the values of your choice.

itoctopus
  • 4,133
  • 4
  • 32
  • 44