You are viewing limited content. For full access, please sign in.

Question

Question

Restrict date to second Saturday of each month

asked on May 18, 2017

Hello,

I am looking for some help restricting a date field within Forms. I would like to have it so the only dates that could be selected would be the second Saturday of each month. Any help would be greatly appreciated.

0 0

Replies

replied on May 18, 2017

Here is a demo for Forms 10.2 and above, it will restrict date picker and check if manual input is valid:

 (set date field with CSS class 'myDate')

$(document).ready(function(){
  function isCorrectDate(n) {
    var t = n.getDay();
    var d = n.getDate();
    return (t==6 && d>7 && d<15);
  }
  function checkDate(n) {
    return[isCorrectDate(n),""];
  }
  function checkField(input, inst) {
    if ($(input).closest('li').hasClass('myDate')) {
      $(input).datepicker("option", {beforeShowDay: checkDate});
    }
  }
  $.datepicker.setDefaults( {beforeShow: checkField} );
  window.Parsley.addValidator('secondsat', {
    validateString: function(value) {
      return isCorrectDate(new Date(value));
    },
    messages: {
      en: 'Not valid date.'
    }
  });
  $('.myDate input').attr('data-parsley-secondsat','');
})

 

1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.