|
CalendarXP.net Support Most forums here are private and invisible to public.
|
View previous topic :: View next topic |
Author |
Message |
calendarxp Site Admin
Joined: 30 Jan 2005 Posts: 409
|
Posted: Tue Feb 15, 2005 6:28 pm Post subject: How to disable days like weekends or holidays? |
|
|
Quite simple - to disable any non-recurring date, you just add a "null" event on that date. e.g.
Code: | fAddEvent(2005,4,1,"disabled date",null); |
To disable recurring dates like weekends, all you need is to put 2 lines of code to the top of fHoliday() function in agenda.js file so that it looks like:
Code: | function fHoliday(y,m,d) {
var dayOfWeek=new Date(y,m-1,d).getDay();
if (dayOfWeek==0||dayOfWeek==6) return ["Weekend is not selectable!",null];
... |
It creates a "null" action agenda for the weekend dates so that they can't be selected. You may also return a formated agenda for the disabled days, e.g. the following code will disable all days with red-green color style except Saturdays for the end date of the DateRange demo in PopCalendarXP:
Code: | function fHoliday(y,m,d) {
var dayOfWeek=new Date(y,m-1,d).getDay();
if (gdCtrl==_endc&&dayOfWeek!=5) return ["Arrivals must be Saturdays!",null,"green","red"];
... |
What if we only want to disable weekends that have no events associated? Also easy - simply move the above code from the top of fHoliday() to the bottom but above the "return" line and modify the condition check as following:
Code: | function fHoliday(y,m,d) {
...
var dayOfWeek=new Date(y,m-1,d).getDay();
if (!rE&&!r&&(dayOfWeek==0||dayOfWeek==6)) return ["Weekend is not selectable!",null];
return rE?rE:r;
} |
The disabled dates may also have various styles, please refer to FAQ - How to set the disabled or out-of-range dates in a special style other than line-through?
You may also be interested in this FAQ - How to change the calendar range after the page being loaded.
_________________ Copyright 2003-2011 Idemfactor Solutions, Inc. All rights reserved.
Last edited by calendarxp on Tue Aug 18, 2009 2:40 pm; edited 2 times in total |
|
Back to top |
|
|
Groundwar
Joined: 11 Jul 2007 Posts: 1
|
Posted: Thu Jul 12, 2007 2:51 pm Post subject: Block certain days |
|
|
What I'm trying to do is associate a point value with a day and block off days that have been booked. This is all being generated with PHP. The code looks like this.
The point is added with fAddEvent and the block for booking is fRemoveEvent & fHoliday. The first aspect is working great (adding a point) however I can block the booked dates.
This is the code I'm using!
Code: |
function fHoliday(y,m,d) {
var rE=fGetEvent(y,m,d), r=null;
var dayOfWeek=new Date(y,m-1,d).getDay();
if (!rE&&!r&&(dayOfWeek==0||dayOfWeek==6)) return ["This date is booked!",null];
return rE?rE:r;
}
function fInitAgenda() {
119
120 // the following presets the date range selected, check the fOnload() in plugins1.js
121 with (gfFlat) {
122
123
124 fAddEvent(2007,07,12,"","","#FFFFFF",null,null,false,"<div class='CALENDAR_POINT'>1</div>");
125 date_array[20070712] = 1;
126
127
128 fAddEvent(2007,07,13,"","","#FFFFFF",null,null,false,"<div class='CALENDAR_POINT'>1</div>");
129 date_array[20070713] = 1;
130
131
132 fAddEvent(2007,07,14,"","","#FFFFFF",null,null,false,"<div class='CALENDAR_POINT'>1</div>");
133 date_array[20070714] = 1;
134
135
136 fAddEvent(2007,07,15,"","","#FFFFFF",null,null,false,"<div class='CALENDAR_POINT'>1</div>");
137 date_array[20070715] = 1;
138
139
140 fAddEvent(2007,07,16,"","","#FFFFFF",null,null,false,"<div class='CALENDAR_POINT'>2</div>");
141 date_array[20070716] = 2;
142
143
144 fAddEvent(2007,07,17,"","","#FFFFFF",null,null,false,"<div class='CALENDAR_POINT'>2</div>");
145 date_array[20070717] = 2;
146
147
148 fAddEvent(2007,07,18,"","","#FFFFFF",null,null,false,"<div class='CALENDAR_POINT'>1</div>");
149 date_array[20070718] = 1;
150
151
152 fAddEvent(2007,07,19,"","","#FFFFFF",null,null,false,"<div class='CALENDAR_POINT'>1</div>");
153 date_array[20070719] = 1;
154
155
156 fAddEvent(2007,07,20,"","","#FFFFFF",null,null,false,"<div class='CALENDAR_POINT'>2</div>");
157 date_array[20070720] = 2;
158
159
160 fAddEvent(2007,07,21,"","","#FFFFFF",null,null,false,"<div class='CALENDAR_POINT'>2</div>");
161 date_array[20070721] = 2;
162
163
164 fAddEvent(2007,07,22,"","","#FFFFFF",null,null,false,"<div class='CALENDAR_POINT'>1</div>");
165 date_array[20070722] = 1;
166
167
168 fAddEvent(2007,07,23,"","","#FFFFFF",null,null,false,"<div class='CALENDAR_POINT'>1</div>");
169 date_array[20070723] = 1;
170
171
172 fAddEvent(2007,07,24,"","","#FFFFFF",null,null,false,"<div class='CALENDAR_POINT'>1</div>");
173 date_array[20070724] = 1;
174
175
176 fAddEvent(2007,07,25,"","","#FFFFFF",null,null,false,"<div class='CALENDAR_POINT'>1</div>");
177 date_array[20070725] = 1;
178
179
180 fAddEvent(2007,07,26,"","","#FFFFFF",null,null,false,"<div class='CALENDAR_POINT'>1</div>");
181 date_array[20070726] = 1;
182
183
184 fInitRange([ [gToday[0],gToday[1],gToday[2]],[2007,07,26] ]);
185
186 fRemoveEvent(2007,07,03);
187 fHoliday(2007,07,03,"",gsAction,"#000000",null,null,false,"");
188 fRemoveEvent(2007,07,04);
189 fHoliday(2007,07,04,"",gsAction,"#000000",null,null,false,"");
190 fRemoveEvent(2007,07,05);
191 fHoliday(2007,07,05,"",gsAction,"#000000",null,null,false,"");
192 fRemoveEvent(2007,07,06);
193 fHoliday(2007,07,06,"",gsAction,"#000000",null,null,false,"");
194 fRemoveEvent(2007,07,07);
195 fHoliday(2007,07,07,"",gsAction,"#000000",null,null,false,"");
196 fRemoveEvent(2007,07,08);
197 fHoliday(2007,07,08,"",gsAction,"#000000",null,null,false,"");
198 fRemoveEvent(2007,07,09);
199 fHoliday(2007,07,09,"",gsAction,"#000000",null,null,false,"");
200 fRemoveEvent(2007,07,10);
201 fHoliday(2007,07,10,"",gsAction,"#000000",null,null,false,"");
202 fRemoveEvent(2007,07,11);
203 fHoliday(2007,07,11,"",gsAction,"#000000",null,null,false,"");
204 fRemoveEvent(2007,07,12);
205 fHoliday(2007,07,12,"",gsAction,"#000000",null,null,false,"");
206
207 fRepaint();
208 }
209}
210</script>
| [/code]
|
|
Back to top |
|
|
calendarxp Site Admin
Joined: 30 Jan 2005 Posts: 409
|
Posted: Thu Jul 12, 2007 6:47 pm Post subject: |
|
|
You are right about adding events, but wrong about blocking.
To block a date, you do not call fRemoveEvent() or fHoliday(). Instead, you should still call fAddEven() but giving it a null value as the action parameter.
e.g. instead of call
Code: | fRemoveEvent(2007,07,03);
fHoliday(2007,07,03,"",gsAction,"#000000",null,null,false,""); |
you should use the following:
Code: | fAddEvent(2007,07,03,"blocked",null); |
_________________ Copyright 2003-2011 Idemfactor Solutions, Inc. All rights reserved. |
|
Back to top |
|
|
tonydeleon
Joined: 18 Dec 2008 Posts: 9
|
Posted: Wed Mar 30, 2011 9:51 pm Post subject: Disable days dinamically from a form |
|
|
function fHoliday(y,m,d) {
var dayOfWeek=new Date(y,m-1,d).getDay();
if (dayOfWeek==0||dayOfWeek==6) return ["Weekend is not selectable!",null];
...
Hello !! using this above, how can I dinamically disable some days ?, maybe from a control value on a web form ?.
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
Copyright 2003- Idemfactor Solutions, Inc. All rights reserved.
Powered by phpBB © 2001, 2005 phpBB Group
|