need to disable Holidays and day in datepicker contact form 7
I saw many solutions but cant disable Sunday Monday and holidays on my contact form 7.trying this solution using and id placing it in functions and footer files but it still displays.Code is
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
jQuery("#datepicker").datepicker({
beforeShowDay: function (date) {
return [date.getDay() == 2 || date.getDay() == 3 || date.getDay() == 4 ||
date.getDay() == 5 || date.getDay() == 6, ""]
}
});
</script>
<label> <span style="color: #000080;"><strong>Your Appointment Date</strong></span>(required)
[date* date-163 id:datepicker]</label>
jquery wordpress user-interface jquery-ui plugins
add a comment |
I saw many solutions but cant disable Sunday Monday and holidays on my contact form 7.trying this solution using and id placing it in functions and footer files but it still displays.Code is
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
jQuery("#datepicker").datepicker({
beforeShowDay: function (date) {
return [date.getDay() == 2 || date.getDay() == 3 || date.getDay() == 4 ||
date.getDay() == 5 || date.getDay() == 6, ""]
}
});
</script>
<label> <span style="color: #000080;"><strong>Your Appointment Date</strong></span>(required)
[date* date-163 id:datepicker]</label>
jquery wordpress user-interface jquery-ui plugins
Welcome to Stack Overflow. In future, it is best to provide a Minimal, Complete, and Verifiable example: stackoverflow.com/help/mcve Also it is best to search before posting a question. Possible Duplicate: stackoverflow.com/questions/53128077/…
– Twisty
Jan 1 at 17:39
It seams you have created adate
input type. This will not work well with datepicker.
– Twisty
Jan 2 at 16:54
add a comment |
I saw many solutions but cant disable Sunday Monday and holidays on my contact form 7.trying this solution using and id placing it in functions and footer files but it still displays.Code is
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
jQuery("#datepicker").datepicker({
beforeShowDay: function (date) {
return [date.getDay() == 2 || date.getDay() == 3 || date.getDay() == 4 ||
date.getDay() == 5 || date.getDay() == 6, ""]
}
});
</script>
<label> <span style="color: #000080;"><strong>Your Appointment Date</strong></span>(required)
[date* date-163 id:datepicker]</label>
jquery wordpress user-interface jquery-ui plugins
I saw many solutions but cant disable Sunday Monday and holidays on my contact form 7.trying this solution using and id placing it in functions and footer files but it still displays.Code is
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
jQuery("#datepicker").datepicker({
beforeShowDay: function (date) {
return [date.getDay() == 2 || date.getDay() == 3 || date.getDay() == 4 ||
date.getDay() == 5 || date.getDay() == 6, ""]
}
});
</script>
<label> <span style="color: #000080;"><strong>Your Appointment Date</strong></span>(required)
[date* date-163 id:datepicker]</label>
jquery wordpress user-interface jquery-ui plugins
jquery wordpress user-interface jquery-ui plugins
edited Jan 2 at 16:52
Twisty
14k11534
14k11534
asked Dec 31 '18 at 3:54
Amit kumarAmit kumar
34
34
Welcome to Stack Overflow. In future, it is best to provide a Minimal, Complete, and Verifiable example: stackoverflow.com/help/mcve Also it is best to search before posting a question. Possible Duplicate: stackoverflow.com/questions/53128077/…
– Twisty
Jan 1 at 17:39
It seams you have created adate
input type. This will not work well with datepicker.
– Twisty
Jan 2 at 16:54
add a comment |
Welcome to Stack Overflow. In future, it is best to provide a Minimal, Complete, and Verifiable example: stackoverflow.com/help/mcve Also it is best to search before posting a question. Possible Duplicate: stackoverflow.com/questions/53128077/…
– Twisty
Jan 1 at 17:39
It seams you have created adate
input type. This will not work well with datepicker.
– Twisty
Jan 2 at 16:54
Welcome to Stack Overflow. In future, it is best to provide a Minimal, Complete, and Verifiable example: stackoverflow.com/help/mcve Also it is best to search before posting a question. Possible Duplicate: stackoverflow.com/questions/53128077/…
– Twisty
Jan 1 at 17:39
Welcome to Stack Overflow. In future, it is best to provide a Minimal, Complete, and Verifiable example: stackoverflow.com/help/mcve Also it is best to search before posting a question. Possible Duplicate: stackoverflow.com/questions/53128077/…
– Twisty
Jan 1 at 17:39
It seams you have created a
date
input type. This will not work well with datepicker.– Twisty
Jan 2 at 16:54
It seams you have created a
date
input type. This will not work well with datepicker.– Twisty
Jan 2 at 16:54
add a comment |
4 Answers
4
active
oldest
votes
Possible Duplicate: How to set maxDate is last day of december on current year?
Consider the following code:
$(function() {
var holidays = {
2019: {
1: {
1: [
false,
"holiday",
"New Year's Day"
],
21: [
false,
"holiday",
"Martin Luther King Jr. Day"
]
},
2: {
18: [
false,
"holiday",
"Presidents' Day"
]
},
5: {
27: [
false,
"holiday",
"Memorial Day"
]
},
7: {
4: [
false,
"holiday",
"Independence Day"
]
},
9: {
2: [
false,
"holiday",
"Labor Day"
]
},
10: {
14: [
false,
"holiday",
"Columbus Day"
]
},
11: {
11: [
false,
"holiday",
"Veterans Day"
],
28: [
false,
"holiday",
"Thanksgiving Day"
]
},
12: {
25: [
false,
"holiday",
"Christmas Day"
],
31: [
false,
"holiday",
"New Year's Eve"
]
}
}
};
$("#datepicker").datepicker({
beforeShowDay: function(date) {
var result = [true, ""];
var yr = $.datepicker.formatDate("yy", date),
mo = $.datepicker.formatDate("m", date),
dy = $.datepicker.formatDate("d", date);
if (date.getDay() == 0 || date.getDay() == 1) {
result[0] = false;
}
if (holidays[yr] !== undefined) {
if (holidays[yr][mo] !== undefined) {
if (holidays[yr][mo][dy] !== undefined) {
console.log("Holiday: " + mo + "/" + dy + "/" + yr);
result = holidays[yr][mo][dy];
}
}
}
return result;
}
});
});
table.ui-datepicker-calendar tbody td.holiday span {
border: 1px solid #222;
}
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<label><span style="color: #000080;"><strong>Your Appointment Date</strong></span>(required)</label><input type="text" id="datepicker">
As you didn't specify which holidays you needed, I copied some old code I had for another answer. This is more complex than is needed. You can simply have an array or dates.
In beforeShowDay
, we assume all days will be [true, ""]
. That way there is always something to return. We then test each day, looking for a day of the week that is 0
or 1
(Sunday or Monday) or looking for a day that has been defined as a Holiday. We then update our result array and return it.
Update
In your WP Code, you will want to ensure you are creating a Text Input and not a Date Input. Also all IDs must be unique, so if you have other datepicker
id's you should consider changing them.
Creating a datepicker on an
<input type="date">
is not supported due to a UI conflict with the native picker.
I would advise the following:
<label> <span style="color: #000080;"><strong>Your Appointment Date</strong></span>(required)</label>[text* date-163 id:datepicker]
Hope that helps.
Sorry for late reply.....Happy New Year!!! i tried this code but still not working.placed just after body in my header and even called through function file.it does display sun n mon...
– Amit kumar
Jan 2 at 9:38
jaipur.onlinewebshop.net/appointment
– Amit kumar
Jan 2 at 10:13
@Amitkumar please provide more details. What is not working specifically? Are there errors in Console? I could not load the link you provided.
– Twisty
Jan 2 at 16:16
@Amitkumar added an update to my answer
– Twisty
Jan 2 at 19:31
@Amitkumar also do you mean you do not want them to appear at all or just be disabled from selection (as they are currently).
– Twisty
Jan 2 at 19:37
|
show 4 more comments
First you need prepare array of holidays then try this one.
var holidays = ["2014-02-27","2014-02-01"];
$( "#from" ).datepicker({
beforeShowDay: function(date){
var datestring = jQuery.datepicker.formatDate('yy-mm-dd', date);
return [ holidays.indexOf(datestring) == -1 ]
}
});
Must return array that contains at least two values:[0]
:true
/false
and[1]
: a CSS class name to add to the date's cell or "" for the default presentation. api.jqueryui.com/datepicker/#option-beforeShowDay Also this does not address OP's question about Sunday and Monday.
– Twisty
Jan 1 at 17:40
add a comment |
you can replace your script with this .. and append your holiday list in removeDays variable.
function disabledays(date) {
var ymd = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
//if u have to disable a list of day
var removeDays = ["2013-6-11","2013-6-31" ];
if ($.inArray(ymd, removeDays) >= 0) {
return [false];
} else {
//Show accept sundays
var day = date.getDay();
return [(day == 1 || day == 2 || day == 3 || day == 4 ||day == 5 ||day == 6 )];
}
}
$(function () {
$('#datepicker').datepicker({
beforeShowDay: disabledays
});
});
If still it dont works then share your console error.
Might consider using the$.datepicker.formatDate()
function: Format a date into a string value with a specified format. Use like so:var ymd = $.datepicker.formatDate("yy-m-d", date);
Might also stick to a RFC format like "yy-mm-dd" for dates in an array. Also return array must contain at least two values:[0]
:true
/false
and[1]
: a CSS class name to add to the date's cell or "" for the default presentation. api.jqueryui.com/datepicker/#option-beforeShowDay
– Twisty
Jan 1 at 17:34
add a comment |
got the answer....
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
Need to delete above script
one need to include jquery only once....adding above script along with
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
makes $(...).datepicker null.
This is adding two different versions of jQuery and is not advised.
– Twisty
Jan 5 at 8:45
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53983437%2fneed-to-disable-holidays-and-day-in-datepicker-contact-form-7%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Possible Duplicate: How to set maxDate is last day of december on current year?
Consider the following code:
$(function() {
var holidays = {
2019: {
1: {
1: [
false,
"holiday",
"New Year's Day"
],
21: [
false,
"holiday",
"Martin Luther King Jr. Day"
]
},
2: {
18: [
false,
"holiday",
"Presidents' Day"
]
},
5: {
27: [
false,
"holiday",
"Memorial Day"
]
},
7: {
4: [
false,
"holiday",
"Independence Day"
]
},
9: {
2: [
false,
"holiday",
"Labor Day"
]
},
10: {
14: [
false,
"holiday",
"Columbus Day"
]
},
11: {
11: [
false,
"holiday",
"Veterans Day"
],
28: [
false,
"holiday",
"Thanksgiving Day"
]
},
12: {
25: [
false,
"holiday",
"Christmas Day"
],
31: [
false,
"holiday",
"New Year's Eve"
]
}
}
};
$("#datepicker").datepicker({
beforeShowDay: function(date) {
var result = [true, ""];
var yr = $.datepicker.formatDate("yy", date),
mo = $.datepicker.formatDate("m", date),
dy = $.datepicker.formatDate("d", date);
if (date.getDay() == 0 || date.getDay() == 1) {
result[0] = false;
}
if (holidays[yr] !== undefined) {
if (holidays[yr][mo] !== undefined) {
if (holidays[yr][mo][dy] !== undefined) {
console.log("Holiday: " + mo + "/" + dy + "/" + yr);
result = holidays[yr][mo][dy];
}
}
}
return result;
}
});
});
table.ui-datepicker-calendar tbody td.holiday span {
border: 1px solid #222;
}
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<label><span style="color: #000080;"><strong>Your Appointment Date</strong></span>(required)</label><input type="text" id="datepicker">
As you didn't specify which holidays you needed, I copied some old code I had for another answer. This is more complex than is needed. You can simply have an array or dates.
In beforeShowDay
, we assume all days will be [true, ""]
. That way there is always something to return. We then test each day, looking for a day of the week that is 0
or 1
(Sunday or Monday) or looking for a day that has been defined as a Holiday. We then update our result array and return it.
Update
In your WP Code, you will want to ensure you are creating a Text Input and not a Date Input. Also all IDs must be unique, so if you have other datepicker
id's you should consider changing them.
Creating a datepicker on an
<input type="date">
is not supported due to a UI conflict with the native picker.
I would advise the following:
<label> <span style="color: #000080;"><strong>Your Appointment Date</strong></span>(required)</label>[text* date-163 id:datepicker]
Hope that helps.
Sorry for late reply.....Happy New Year!!! i tried this code but still not working.placed just after body in my header and even called through function file.it does display sun n mon...
– Amit kumar
Jan 2 at 9:38
jaipur.onlinewebshop.net/appointment
– Amit kumar
Jan 2 at 10:13
@Amitkumar please provide more details. What is not working specifically? Are there errors in Console? I could not load the link you provided.
– Twisty
Jan 2 at 16:16
@Amitkumar added an update to my answer
– Twisty
Jan 2 at 19:31
@Amitkumar also do you mean you do not want them to appear at all or just be disabled from selection (as they are currently).
– Twisty
Jan 2 at 19:37
|
show 4 more comments
Possible Duplicate: How to set maxDate is last day of december on current year?
Consider the following code:
$(function() {
var holidays = {
2019: {
1: {
1: [
false,
"holiday",
"New Year's Day"
],
21: [
false,
"holiday",
"Martin Luther King Jr. Day"
]
},
2: {
18: [
false,
"holiday",
"Presidents' Day"
]
},
5: {
27: [
false,
"holiday",
"Memorial Day"
]
},
7: {
4: [
false,
"holiday",
"Independence Day"
]
},
9: {
2: [
false,
"holiday",
"Labor Day"
]
},
10: {
14: [
false,
"holiday",
"Columbus Day"
]
},
11: {
11: [
false,
"holiday",
"Veterans Day"
],
28: [
false,
"holiday",
"Thanksgiving Day"
]
},
12: {
25: [
false,
"holiday",
"Christmas Day"
],
31: [
false,
"holiday",
"New Year's Eve"
]
}
}
};
$("#datepicker").datepicker({
beforeShowDay: function(date) {
var result = [true, ""];
var yr = $.datepicker.formatDate("yy", date),
mo = $.datepicker.formatDate("m", date),
dy = $.datepicker.formatDate("d", date);
if (date.getDay() == 0 || date.getDay() == 1) {
result[0] = false;
}
if (holidays[yr] !== undefined) {
if (holidays[yr][mo] !== undefined) {
if (holidays[yr][mo][dy] !== undefined) {
console.log("Holiday: " + mo + "/" + dy + "/" + yr);
result = holidays[yr][mo][dy];
}
}
}
return result;
}
});
});
table.ui-datepicker-calendar tbody td.holiday span {
border: 1px solid #222;
}
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<label><span style="color: #000080;"><strong>Your Appointment Date</strong></span>(required)</label><input type="text" id="datepicker">
As you didn't specify which holidays you needed, I copied some old code I had for another answer. This is more complex than is needed. You can simply have an array or dates.
In beforeShowDay
, we assume all days will be [true, ""]
. That way there is always something to return. We then test each day, looking for a day of the week that is 0
or 1
(Sunday or Monday) or looking for a day that has been defined as a Holiday. We then update our result array and return it.
Update
In your WP Code, you will want to ensure you are creating a Text Input and not a Date Input. Also all IDs must be unique, so if you have other datepicker
id's you should consider changing them.
Creating a datepicker on an
<input type="date">
is not supported due to a UI conflict with the native picker.
I would advise the following:
<label> <span style="color: #000080;"><strong>Your Appointment Date</strong></span>(required)</label>[text* date-163 id:datepicker]
Hope that helps.
Sorry for late reply.....Happy New Year!!! i tried this code but still not working.placed just after body in my header and even called through function file.it does display sun n mon...
– Amit kumar
Jan 2 at 9:38
jaipur.onlinewebshop.net/appointment
– Amit kumar
Jan 2 at 10:13
@Amitkumar please provide more details. What is not working specifically? Are there errors in Console? I could not load the link you provided.
– Twisty
Jan 2 at 16:16
@Amitkumar added an update to my answer
– Twisty
Jan 2 at 19:31
@Amitkumar also do you mean you do not want them to appear at all or just be disabled from selection (as they are currently).
– Twisty
Jan 2 at 19:37
|
show 4 more comments
Possible Duplicate: How to set maxDate is last day of december on current year?
Consider the following code:
$(function() {
var holidays = {
2019: {
1: {
1: [
false,
"holiday",
"New Year's Day"
],
21: [
false,
"holiday",
"Martin Luther King Jr. Day"
]
},
2: {
18: [
false,
"holiday",
"Presidents' Day"
]
},
5: {
27: [
false,
"holiday",
"Memorial Day"
]
},
7: {
4: [
false,
"holiday",
"Independence Day"
]
},
9: {
2: [
false,
"holiday",
"Labor Day"
]
},
10: {
14: [
false,
"holiday",
"Columbus Day"
]
},
11: {
11: [
false,
"holiday",
"Veterans Day"
],
28: [
false,
"holiday",
"Thanksgiving Day"
]
},
12: {
25: [
false,
"holiday",
"Christmas Day"
],
31: [
false,
"holiday",
"New Year's Eve"
]
}
}
};
$("#datepicker").datepicker({
beforeShowDay: function(date) {
var result = [true, ""];
var yr = $.datepicker.formatDate("yy", date),
mo = $.datepicker.formatDate("m", date),
dy = $.datepicker.formatDate("d", date);
if (date.getDay() == 0 || date.getDay() == 1) {
result[0] = false;
}
if (holidays[yr] !== undefined) {
if (holidays[yr][mo] !== undefined) {
if (holidays[yr][mo][dy] !== undefined) {
console.log("Holiday: " + mo + "/" + dy + "/" + yr);
result = holidays[yr][mo][dy];
}
}
}
return result;
}
});
});
table.ui-datepicker-calendar tbody td.holiday span {
border: 1px solid #222;
}
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<label><span style="color: #000080;"><strong>Your Appointment Date</strong></span>(required)</label><input type="text" id="datepicker">
As you didn't specify which holidays you needed, I copied some old code I had for another answer. This is more complex than is needed. You can simply have an array or dates.
In beforeShowDay
, we assume all days will be [true, ""]
. That way there is always something to return. We then test each day, looking for a day of the week that is 0
or 1
(Sunday or Monday) or looking for a day that has been defined as a Holiday. We then update our result array and return it.
Update
In your WP Code, you will want to ensure you are creating a Text Input and not a Date Input. Also all IDs must be unique, so if you have other datepicker
id's you should consider changing them.
Creating a datepicker on an
<input type="date">
is not supported due to a UI conflict with the native picker.
I would advise the following:
<label> <span style="color: #000080;"><strong>Your Appointment Date</strong></span>(required)</label>[text* date-163 id:datepicker]
Hope that helps.
Possible Duplicate: How to set maxDate is last day of december on current year?
Consider the following code:
$(function() {
var holidays = {
2019: {
1: {
1: [
false,
"holiday",
"New Year's Day"
],
21: [
false,
"holiday",
"Martin Luther King Jr. Day"
]
},
2: {
18: [
false,
"holiday",
"Presidents' Day"
]
},
5: {
27: [
false,
"holiday",
"Memorial Day"
]
},
7: {
4: [
false,
"holiday",
"Independence Day"
]
},
9: {
2: [
false,
"holiday",
"Labor Day"
]
},
10: {
14: [
false,
"holiday",
"Columbus Day"
]
},
11: {
11: [
false,
"holiday",
"Veterans Day"
],
28: [
false,
"holiday",
"Thanksgiving Day"
]
},
12: {
25: [
false,
"holiday",
"Christmas Day"
],
31: [
false,
"holiday",
"New Year's Eve"
]
}
}
};
$("#datepicker").datepicker({
beforeShowDay: function(date) {
var result = [true, ""];
var yr = $.datepicker.formatDate("yy", date),
mo = $.datepicker.formatDate("m", date),
dy = $.datepicker.formatDate("d", date);
if (date.getDay() == 0 || date.getDay() == 1) {
result[0] = false;
}
if (holidays[yr] !== undefined) {
if (holidays[yr][mo] !== undefined) {
if (holidays[yr][mo][dy] !== undefined) {
console.log("Holiday: " + mo + "/" + dy + "/" + yr);
result = holidays[yr][mo][dy];
}
}
}
return result;
}
});
});
table.ui-datepicker-calendar tbody td.holiday span {
border: 1px solid #222;
}
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<label><span style="color: #000080;"><strong>Your Appointment Date</strong></span>(required)</label><input type="text" id="datepicker">
As you didn't specify which holidays you needed, I copied some old code I had for another answer. This is more complex than is needed. You can simply have an array or dates.
In beforeShowDay
, we assume all days will be [true, ""]
. That way there is always something to return. We then test each day, looking for a day of the week that is 0
or 1
(Sunday or Monday) or looking for a day that has been defined as a Holiday. We then update our result array and return it.
Update
In your WP Code, you will want to ensure you are creating a Text Input and not a Date Input. Also all IDs must be unique, so if you have other datepicker
id's you should consider changing them.
Creating a datepicker on an
<input type="date">
is not supported due to a UI conflict with the native picker.
I would advise the following:
<label> <span style="color: #000080;"><strong>Your Appointment Date</strong></span>(required)</label>[text* date-163 id:datepicker]
Hope that helps.
$(function() {
var holidays = {
2019: {
1: {
1: [
false,
"holiday",
"New Year's Day"
],
21: [
false,
"holiday",
"Martin Luther King Jr. Day"
]
},
2: {
18: [
false,
"holiday",
"Presidents' Day"
]
},
5: {
27: [
false,
"holiday",
"Memorial Day"
]
},
7: {
4: [
false,
"holiday",
"Independence Day"
]
},
9: {
2: [
false,
"holiday",
"Labor Day"
]
},
10: {
14: [
false,
"holiday",
"Columbus Day"
]
},
11: {
11: [
false,
"holiday",
"Veterans Day"
],
28: [
false,
"holiday",
"Thanksgiving Day"
]
},
12: {
25: [
false,
"holiday",
"Christmas Day"
],
31: [
false,
"holiday",
"New Year's Eve"
]
}
}
};
$("#datepicker").datepicker({
beforeShowDay: function(date) {
var result = [true, ""];
var yr = $.datepicker.formatDate("yy", date),
mo = $.datepicker.formatDate("m", date),
dy = $.datepicker.formatDate("d", date);
if (date.getDay() == 0 || date.getDay() == 1) {
result[0] = false;
}
if (holidays[yr] !== undefined) {
if (holidays[yr][mo] !== undefined) {
if (holidays[yr][mo][dy] !== undefined) {
console.log("Holiday: " + mo + "/" + dy + "/" + yr);
result = holidays[yr][mo][dy];
}
}
}
return result;
}
});
});
table.ui-datepicker-calendar tbody td.holiday span {
border: 1px solid #222;
}
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<label><span style="color: #000080;"><strong>Your Appointment Date</strong></span>(required)</label><input type="text" id="datepicker">
$(function() {
var holidays = {
2019: {
1: {
1: [
false,
"holiday",
"New Year's Day"
],
21: [
false,
"holiday",
"Martin Luther King Jr. Day"
]
},
2: {
18: [
false,
"holiday",
"Presidents' Day"
]
},
5: {
27: [
false,
"holiday",
"Memorial Day"
]
},
7: {
4: [
false,
"holiday",
"Independence Day"
]
},
9: {
2: [
false,
"holiday",
"Labor Day"
]
},
10: {
14: [
false,
"holiday",
"Columbus Day"
]
},
11: {
11: [
false,
"holiday",
"Veterans Day"
],
28: [
false,
"holiday",
"Thanksgiving Day"
]
},
12: {
25: [
false,
"holiday",
"Christmas Day"
],
31: [
false,
"holiday",
"New Year's Eve"
]
}
}
};
$("#datepicker").datepicker({
beforeShowDay: function(date) {
var result = [true, ""];
var yr = $.datepicker.formatDate("yy", date),
mo = $.datepicker.formatDate("m", date),
dy = $.datepicker.formatDate("d", date);
if (date.getDay() == 0 || date.getDay() == 1) {
result[0] = false;
}
if (holidays[yr] !== undefined) {
if (holidays[yr][mo] !== undefined) {
if (holidays[yr][mo][dy] !== undefined) {
console.log("Holiday: " + mo + "/" + dy + "/" + yr);
result = holidays[yr][mo][dy];
}
}
}
return result;
}
});
});
table.ui-datepicker-calendar tbody td.holiday span {
border: 1px solid #222;
}
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<label><span style="color: #000080;"><strong>Your Appointment Date</strong></span>(required)</label><input type="text" id="datepicker">
edited Jan 2 at 19:31
answered Jan 1 at 17:26
TwistyTwisty
14k11534
14k11534
Sorry for late reply.....Happy New Year!!! i tried this code but still not working.placed just after body in my header and even called through function file.it does display sun n mon...
– Amit kumar
Jan 2 at 9:38
jaipur.onlinewebshop.net/appointment
– Amit kumar
Jan 2 at 10:13
@Amitkumar please provide more details. What is not working specifically? Are there errors in Console? I could not load the link you provided.
– Twisty
Jan 2 at 16:16
@Amitkumar added an update to my answer
– Twisty
Jan 2 at 19:31
@Amitkumar also do you mean you do not want them to appear at all or just be disabled from selection (as they are currently).
– Twisty
Jan 2 at 19:37
|
show 4 more comments
Sorry for late reply.....Happy New Year!!! i tried this code but still not working.placed just after body in my header and even called through function file.it does display sun n mon...
– Amit kumar
Jan 2 at 9:38
jaipur.onlinewebshop.net/appointment
– Amit kumar
Jan 2 at 10:13
@Amitkumar please provide more details. What is not working specifically? Are there errors in Console? I could not load the link you provided.
– Twisty
Jan 2 at 16:16
@Amitkumar added an update to my answer
– Twisty
Jan 2 at 19:31
@Amitkumar also do you mean you do not want them to appear at all or just be disabled from selection (as they are currently).
– Twisty
Jan 2 at 19:37
Sorry for late reply.....Happy New Year!!! i tried this code but still not working.placed just after body in my header and even called through function file.it does display sun n mon...
– Amit kumar
Jan 2 at 9:38
Sorry for late reply.....Happy New Year!!! i tried this code but still not working.placed just after body in my header and even called through function file.it does display sun n mon...
– Amit kumar
Jan 2 at 9:38
jaipur.onlinewebshop.net/appointment
– Amit kumar
Jan 2 at 10:13
jaipur.onlinewebshop.net/appointment
– Amit kumar
Jan 2 at 10:13
@Amitkumar please provide more details. What is not working specifically? Are there errors in Console? I could not load the link you provided.
– Twisty
Jan 2 at 16:16
@Amitkumar please provide more details. What is not working specifically? Are there errors in Console? I could not load the link you provided.
– Twisty
Jan 2 at 16:16
@Amitkumar added an update to my answer
– Twisty
Jan 2 at 19:31
@Amitkumar added an update to my answer
– Twisty
Jan 2 at 19:31
@Amitkumar also do you mean you do not want them to appear at all or just be disabled from selection (as they are currently).
– Twisty
Jan 2 at 19:37
@Amitkumar also do you mean you do not want them to appear at all or just be disabled from selection (as they are currently).
– Twisty
Jan 2 at 19:37
|
show 4 more comments
First you need prepare array of holidays then try this one.
var holidays = ["2014-02-27","2014-02-01"];
$( "#from" ).datepicker({
beforeShowDay: function(date){
var datestring = jQuery.datepicker.formatDate('yy-mm-dd', date);
return [ holidays.indexOf(datestring) == -1 ]
}
});
Must return array that contains at least two values:[0]
:true
/false
and[1]
: a CSS class name to add to the date's cell or "" for the default presentation. api.jqueryui.com/datepicker/#option-beforeShowDay Also this does not address OP's question about Sunday and Monday.
– Twisty
Jan 1 at 17:40
add a comment |
First you need prepare array of holidays then try this one.
var holidays = ["2014-02-27","2014-02-01"];
$( "#from" ).datepicker({
beforeShowDay: function(date){
var datestring = jQuery.datepicker.formatDate('yy-mm-dd', date);
return [ holidays.indexOf(datestring) == -1 ]
}
});
Must return array that contains at least two values:[0]
:true
/false
and[1]
: a CSS class name to add to the date's cell or "" for the default presentation. api.jqueryui.com/datepicker/#option-beforeShowDay Also this does not address OP's question about Sunday and Monday.
– Twisty
Jan 1 at 17:40
add a comment |
First you need prepare array of holidays then try this one.
var holidays = ["2014-02-27","2014-02-01"];
$( "#from" ).datepicker({
beforeShowDay: function(date){
var datestring = jQuery.datepicker.formatDate('yy-mm-dd', date);
return [ holidays.indexOf(datestring) == -1 ]
}
});
First you need prepare array of holidays then try this one.
var holidays = ["2014-02-27","2014-02-01"];
$( "#from" ).datepicker({
beforeShowDay: function(date){
var datestring = jQuery.datepicker.formatDate('yy-mm-dd', date);
return [ holidays.indexOf(datestring) == -1 ]
}
});
answered Dec 31 '18 at 4:26
MaheskumarMaheskumar
1215
1215
Must return array that contains at least two values:[0]
:true
/false
and[1]
: a CSS class name to add to the date's cell or "" for the default presentation. api.jqueryui.com/datepicker/#option-beforeShowDay Also this does not address OP's question about Sunday and Monday.
– Twisty
Jan 1 at 17:40
add a comment |
Must return array that contains at least two values:[0]
:true
/false
and[1]
: a CSS class name to add to the date's cell or "" for the default presentation. api.jqueryui.com/datepicker/#option-beforeShowDay Also this does not address OP's question about Sunday and Monday.
– Twisty
Jan 1 at 17:40
Must return array that contains at least two values:
[0]
: true
/false
and [1]
: a CSS class name to add to the date's cell or "" for the default presentation. api.jqueryui.com/datepicker/#option-beforeShowDay Also this does not address OP's question about Sunday and Monday.– Twisty
Jan 1 at 17:40
Must return array that contains at least two values:
[0]
: true
/false
and [1]
: a CSS class name to add to the date's cell or "" for the default presentation. api.jqueryui.com/datepicker/#option-beforeShowDay Also this does not address OP's question about Sunday and Monday.– Twisty
Jan 1 at 17:40
add a comment |
you can replace your script with this .. and append your holiday list in removeDays variable.
function disabledays(date) {
var ymd = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
//if u have to disable a list of day
var removeDays = ["2013-6-11","2013-6-31" ];
if ($.inArray(ymd, removeDays) >= 0) {
return [false];
} else {
//Show accept sundays
var day = date.getDay();
return [(day == 1 || day == 2 || day == 3 || day == 4 ||day == 5 ||day == 6 )];
}
}
$(function () {
$('#datepicker').datepicker({
beforeShowDay: disabledays
});
});
If still it dont works then share your console error.
Might consider using the$.datepicker.formatDate()
function: Format a date into a string value with a specified format. Use like so:var ymd = $.datepicker.formatDate("yy-m-d", date);
Might also stick to a RFC format like "yy-mm-dd" for dates in an array. Also return array must contain at least two values:[0]
:true
/false
and[1]
: a CSS class name to add to the date's cell or "" for the default presentation. api.jqueryui.com/datepicker/#option-beforeShowDay
– Twisty
Jan 1 at 17:34
add a comment |
you can replace your script with this .. and append your holiday list in removeDays variable.
function disabledays(date) {
var ymd = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
//if u have to disable a list of day
var removeDays = ["2013-6-11","2013-6-31" ];
if ($.inArray(ymd, removeDays) >= 0) {
return [false];
} else {
//Show accept sundays
var day = date.getDay();
return [(day == 1 || day == 2 || day == 3 || day == 4 ||day == 5 ||day == 6 )];
}
}
$(function () {
$('#datepicker').datepicker({
beforeShowDay: disabledays
});
});
If still it dont works then share your console error.
Might consider using the$.datepicker.formatDate()
function: Format a date into a string value with a specified format. Use like so:var ymd = $.datepicker.formatDate("yy-m-d", date);
Might also stick to a RFC format like "yy-mm-dd" for dates in an array. Also return array must contain at least two values:[0]
:true
/false
and[1]
: a CSS class name to add to the date's cell or "" for the default presentation. api.jqueryui.com/datepicker/#option-beforeShowDay
– Twisty
Jan 1 at 17:34
add a comment |
you can replace your script with this .. and append your holiday list in removeDays variable.
function disabledays(date) {
var ymd = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
//if u have to disable a list of day
var removeDays = ["2013-6-11","2013-6-31" ];
if ($.inArray(ymd, removeDays) >= 0) {
return [false];
} else {
//Show accept sundays
var day = date.getDay();
return [(day == 1 || day == 2 || day == 3 || day == 4 ||day == 5 ||day == 6 )];
}
}
$(function () {
$('#datepicker').datepicker({
beforeShowDay: disabledays
});
});
If still it dont works then share your console error.
you can replace your script with this .. and append your holiday list in removeDays variable.
function disabledays(date) {
var ymd = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
//if u have to disable a list of day
var removeDays = ["2013-6-11","2013-6-31" ];
if ($.inArray(ymd, removeDays) >= 0) {
return [false];
} else {
//Show accept sundays
var day = date.getDay();
return [(day == 1 || day == 2 || day == 3 || day == 4 ||day == 5 ||day == 6 )];
}
}
$(function () {
$('#datepicker').datepicker({
beforeShowDay: disabledays
});
});
If still it dont works then share your console error.
answered Dec 31 '18 at 9:52
NikunjNikunj
709
709
Might consider using the$.datepicker.formatDate()
function: Format a date into a string value with a specified format. Use like so:var ymd = $.datepicker.formatDate("yy-m-d", date);
Might also stick to a RFC format like "yy-mm-dd" for dates in an array. Also return array must contain at least two values:[0]
:true
/false
and[1]
: a CSS class name to add to the date's cell or "" for the default presentation. api.jqueryui.com/datepicker/#option-beforeShowDay
– Twisty
Jan 1 at 17:34
add a comment |
Might consider using the$.datepicker.formatDate()
function: Format a date into a string value with a specified format. Use like so:var ymd = $.datepicker.formatDate("yy-m-d", date);
Might also stick to a RFC format like "yy-mm-dd" for dates in an array. Also return array must contain at least two values:[0]
:true
/false
and[1]
: a CSS class name to add to the date's cell or "" for the default presentation. api.jqueryui.com/datepicker/#option-beforeShowDay
– Twisty
Jan 1 at 17:34
Might consider using the
$.datepicker.formatDate()
function: Format a date into a string value with a specified format. Use like so: var ymd = $.datepicker.formatDate("yy-m-d", date);
Might also stick to a RFC format like "yy-mm-dd" for dates in an array. Also return array must contain at least two values: [0]
: true
/false
and [1]
: a CSS class name to add to the date's cell or "" for the default presentation. api.jqueryui.com/datepicker/#option-beforeShowDay– Twisty
Jan 1 at 17:34
Might consider using the
$.datepicker.formatDate()
function: Format a date into a string value with a specified format. Use like so: var ymd = $.datepicker.formatDate("yy-m-d", date);
Might also stick to a RFC format like "yy-mm-dd" for dates in an array. Also return array must contain at least two values: [0]
: true
/false
and [1]
: a CSS class name to add to the date's cell or "" for the default presentation. api.jqueryui.com/datepicker/#option-beforeShowDay– Twisty
Jan 1 at 17:34
add a comment |
got the answer....
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
Need to delete above script
one need to include jquery only once....adding above script along with
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
makes $(...).datepicker null.
This is adding two different versions of jQuery and is not advised.
– Twisty
Jan 5 at 8:45
add a comment |
got the answer....
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
Need to delete above script
one need to include jquery only once....adding above script along with
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
makes $(...).datepicker null.
This is adding two different versions of jQuery and is not advised.
– Twisty
Jan 5 at 8:45
add a comment |
got the answer....
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
Need to delete above script
one need to include jquery only once....adding above script along with
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
makes $(...).datepicker null.
got the answer....
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
Need to delete above script
one need to include jquery only once....adding above script along with
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
makes $(...).datepicker null.
edited Jan 5 at 8:47
answered Jan 5 at 8:38
Amit kumarAmit kumar
34
34
This is adding two different versions of jQuery and is not advised.
– Twisty
Jan 5 at 8:45
add a comment |
This is adding two different versions of jQuery and is not advised.
– Twisty
Jan 5 at 8:45
This is adding two different versions of jQuery and is not advised.
– Twisty
Jan 5 at 8:45
This is adding two different versions of jQuery and is not advised.
– Twisty
Jan 5 at 8:45
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53983437%2fneed-to-disable-holidays-and-day-in-datepicker-contact-form-7%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Welcome to Stack Overflow. In future, it is best to provide a Minimal, Complete, and Verifiable example: stackoverflow.com/help/mcve Also it is best to search before posting a question. Possible Duplicate: stackoverflow.com/questions/53128077/…
– Twisty
Jan 1 at 17:39
It seams you have created a
date
input type. This will not work well with datepicker.– Twisty
Jan 2 at 16:54