PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Where to add datepicker custom javascript?

  1. Fika
    Member

    Hello,

    I am trying to customize by datepicker to block national holidays and some other useful dates which I don't want people to be allowed to select. I don't see this functionality in Gravity Forms datepicker so I would like to know where to add my javascript?

    I have searched the forums and it says put in in your page template. I don't want to get out of my depth by just placing it anywhere. Would you be able to direct me to the template I should be editing to add this code or maybe I can do it directly in gravity forms via some snippet or something?

    Thanks

    Code I am trying to add:

    <script type="text/javascript">
    jQuery.noConflict();
      jQuery(document).ready(function($) {
    
    $(".selector").datepicker({ beforeShowDay: nationalDays})   
    
    natDays = [
      [1, 26, 'au'], [2, 6, 'nz'], [3, 17, 'ie'],
      [4, 27, 'za'], [5, 25, 'ar'], [6, 6, 'se'],
      [7, 4, 'us'], [8, 17, 'id'], [9, 7, 'br'],
      [10, 1, 'cn'], [11, 22, 'lb'], [12, 12, 'ke']
    ];
    
    function nationalDays(date) {
        for (i = 0; i < natDays.length; i++) {
          if (date.getMonth() == natDays[i][0] - 1
              && date.getDate() == natDays[i][1]) {
            return [false, natDays[i][2] + '_day'];
          }
        }
      return [true, ''];
    }
    
      });
    </script>

    Code grabbed from here http://stackoverflow.com/questions/501943/can-the-jquery-ui-datepicker-be-made-to-disable-saturdays-and-sundays-and-holid

    Posted 12 years ago on Thursday March 15, 2012 | Permalink
  2. Well, I would think you could try it a couple of ways. You could make an isolated page template for forms that does just include this script there and there only to avoid it being placed globally.

    Or you could place it globally in the head or footer - does your theme already have any sort of JS functions file?

    Posted 12 years ago on Thursday March 15, 2012 | Permalink
  3. Fika
    Member

    Hi Rob,

    Thanks for the suggestions. I actually found it easier to get a plugin "CSS & JavaScript Toolbox" which allows me to insert code snippets to the templates without mucking around in the code. That also helps me out with theme updates not overiding my changes.

    Only issue I have left is formatting the date the way I need to . I asked about that here http://www.gravityhelp.com/forums/topic/how-to-format-date-as-full-dd-d-mm-yy-in-date-picker if you have any suggestions would be great to hear...

    Cheers

    Plugin Ref: http://wordpress.org/extend/plugins/css-javascript-toolbox/

    Posted 12 years ago on Thursday March 15, 2012 | Permalink
  4. Fika
    Member

    Hi Rob,

    After figuring out the exact JavaScript I need to use I am getting a conflict (i think) when loading the script globally in the header or footer using the above WP plugin.

    It would be good if I can do it the way you were suggesting?

    Posted 12 years ago on Friday March 16, 2012 | Permalink
  5. Fika
    Member

    Actually I was able to get this all working in the end.

    Thanks

    Posted 12 years ago on Tuesday March 20, 2012 | Permalink
  6. Awesome, thanks for letting us know.

    Posted 12 years ago on Tuesday March 20, 2012 | Permalink

This topic has been resolved and has been closed to new replies.