Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Disable monday and tuesday #37

Closed
Joneses opened this Issue Jan 25, 2013 · 18 comments

Comments

10 participants

Joneses commented Jan 25, 2013

Hi, Is it possbiel to disable mondays and tuesdays?

Owner

relu commented Jan 28, 2013

Hello,

You can do that using a few lines of JavaScript. Take a look here.

Make sure to use the id attribute for your date field: [date ... id:someid]
You would replace the ​$("#datepicker").datepicker({ part with ​$("#someid").datepicker({

@relu relu closed this Jan 28, 2013

Thor78 commented Feb 17, 2013

I might have a stupid question, but I am an absolute newbie and have no clue on coding. So I have to admit you guys are awesome and do a great job.

So, my question is. Where do I put the code to make it work?? It is not working on my site. Thanks a lot!!

I got the datepicker "Wunsch-Lieferdatum" implemented here: http://makeurcake.ch/cake-u-lator/

Owner

relu commented Feb 17, 2013

@thor79 add this to you form editor, it should work.

jQuery(function($){
  ​$("#lieferdatum").datepicker({
    beforeShowDay: function(date) {
      var day = date.getDay();
      return [(day != 1 && day != 2)];
    }
  })​​​​​;​
});

day != 1 means day is not Monday. I think you can figure out the rest based on this logic :)

N.B. You should update WordPress to 3.5.

Joneses commented Feb 20, 2013

Hi, Do you have some more info on how to get this to work? I just cant make it work, I tried nearly everything.

Thor78 commented Mar 6, 2013

Here is the code I am using. You can see the example here: http://makeurcake.ch/cake-u-lator/

Put the following code into your header tags. While using the dates, I am able to disbale any date I need to. Vacation, holidays, etc.

Hope that helps.

Cheers!

<head>

<?php
//jQuery
if($post->ID==16){
        //this code only runs when the current page is our contact page!
        //TURN TEXT FIELD INTO DATEPICKER
        echo '<script type="text/javascript">';

        //set vacation dates here
        echo 'var unavailableDates = ["9-5-2013", "10-5-2013", "11-5-2013", "12-5-2013", "13-5-2013", "14-5-2013", "15-5-2013", "16-5-2013", "17-5-2013", "18-5-2013", "19-5-2013", "20-5-2013", "21-5-2013", "22-5-2013", "23-5-2013", "24-5-2013"];';
        //vacation ends here

        echo 'jQuery(function($){';
        echo '$( "#lieferdatum" ).datepicker({';
        echo 'minDate: 5,'; 
        echo 'beforeShowDay: function(date) {';
        echo 'dmy = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear();';
        echo 'if ($.inArray(dmy, unavailableDates) == -1) {';
        echo 'return [true, ""];';
        echo '} else {';
        echo 'return [false, "", "Unavailable"];';
        echo '}';
        echo '}';
        echo '});';
        echo '});';
        echo '</script>';
}
?>

</head>
Owner

relu commented Mar 10, 2013

@Thor78 I "fixed" your code block. Just an advice, don't use echo like that, you could have done:

if ($post->ID == 16) { 
?>
   <script>
       JS CODE GOES HERE
   </script>
<?php 
}

Thor78 commented Mar 10, 2013

@relu Works like a charm. Thanks for the advice.

Hi everybody!

I have the same problem with the Datepicker form and I have no idea how to solve it.

I understand what you are saying and the changed code makes sense but where do I change it? Which file do I need to open and edit? Is it the header.php?

What I need to do is disable Sundays, holidays and the dates before today on this website: http://rist-da-vinci.de/reservieren/

Thank you so much for your help!
Cheers!

Owner

relu commented Jan 15, 2014

First, make sure you set an id for your date field also setting min-date to 0 i.e. [date ... id:someid min-date:0]
Add this to the bottom of your contact form (in the form editor, where you have your shortcodes). If it doesn't work in the form editor, add it to your theme's footer.php before the </body> closing tag.

<script>
jQuery(function($){
  var holidayDates = ["1-5", "25-12"]; // define your holidays here
  $("#someid").datepicker({
    beforeShowDay: function(date) {
    var day = date.getDay(),
          dm = date.getDate() + "-" + (date.getMonth() + 1);
    var isHoliday = ($.inArray(dm, holidayDates) != -1);
    return [day != 0 && !isHoliday];
  }});
});
</script>

Awesome! Thank you so much relu!

Does this solution possibly also works with $('input [name=some-field]') instead of the #id of the datepicker? As per my other question ('#99) I cannot get the form field to either display or accept values when an id is given in the shortcode. Whether the field is displayed or not at all appears to depend on the order of arguments given in the shortcode.

Also, I cannot disable any dates with this code and an "input"-selector.

Hi guys, I added the id in the form 7 editor and tried to add the script to the form 7 additional settings and to the footer.php, but there is no way to make it work.

Can anybody help me?

My contact form 7 settings: [date* id:16 min-date:0 date min:today "Data"]

The script under footer.php:

<script>
jQuery(function($){
  var holidayDates = ["1-5", "25-12"]; // define your holidays here
  $("#16").datepicker({
    beforeShowDay: function(date) {
    var day = date.getDay(),
          dm = date.getDate() + "-" + (date.getMonth() + 1);
    var isHoliday = ($.inArray(dm, holidayDates) != -1);
    return [day != 0 && !isHoliday];
  }});
});
    </script>

Thanks!

naazg commented Dec 22, 2016

Hello, Sorry i know it take too long. but i used the above code to disable Friday and Saturday as a holidays.. I tried with the option available in the plugin but its only disabling Sat and Sun.. while here the holidays are Fri and Sat.. The code works great.. but the issue with this is it disable the time bar. Now i am unable to select the timing.... can anyone help me.

mdkz1 commented Feb 22, 2017

@relu Thanks man .....

spooner-street commented May 23, 2017

Can anyone help me modify this code? I've been trying to get relu's example to work for the past two days, without much luck.

Specifically, I want to disable all days that aren't Wednesday. (I know, at this point, it's a bit pointless to even have a calendar, but that's what I've been asked to do.)

If anyone could post the exact code I need to insert, you'd really be helping me out. Thank you in advance!

naazg commented May 25, 2017

Hello Spooner street,

Below is the code. I disabled friday and saturday using the below code

$("#56off").datepicker({
    beforeShowDay: function(date) {
        var day = date.getDay();
        return [(day != 5 && day != 6)];
    }
});

where #56off is the id of the date field... if you still couldn't figure out let me know i will try to write a code for you which will enable Wednesday only. but the code is very easy you can understand.

Hope that's help.

Naaz

Thanks for reaching out to help, naazg. I'll give this a try.

Hi @relu , hi @naazg , I need to disable by default some months, so I found the code to disable specific days of the week and I would like to use is as starting to disable months.
The problem is even the code I found here doesn't work, it doesn't disable days :(
Could you please help me?
Many thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment