Bootstrap/javascript/jquery - Further manipulating StartDates and EndDates with datepicker

I'm currently using this script to stop the end date at the next sunday on a datepicker control (following the start date.)
I want to amend it so that if the StartDate selected is a Sunday, only that day can be selected.

i.e. March 26th, 2017 is selected as the start date.
The only available date to be selected for EndDate would be March 26th, 2017.

var dateFormat = "mm/dd/yy";
$(document).ready(function(){
  var from = $(".start").datepicker({
    changeMonth: true,
   dateFormat: dateFormat,
    numberOfMonths: 1,
    onSelect: function(dt, inst){
      var fromDt = $(this).datepicker("getDate");
      var nextSunday = new Date(fromDt.getTime());
      nextSunday.setDate(nextSunday.getDate() + 7 - fromDt.getDay());

      to.datepicker("option", "minDate", dt);
      to.datepicker("option", "maxDate", nextSunday);
      loadHours();
    }
  });

  var to = $(".end").datepicker({
    changeMonth: true,
    dateFormat: dateFormat,
    numberOfMonths: 1,
    onSelect: function(dt, inst){
        from.datepicker("option", "maxDate", dt);
        loadHours();
    }
  });
});

Open in new window

Mike MillerSoftware EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pravin AsarPrincipal Systems EngineerCommented:
I think you can simplify the Specific Day Pick enable by using  date picker event/display handler

$("#dp").datepicker({
  beforeShowDay: function(date){ return [date.getDay() == 0,""]}
});

Look at the working example @

http://jsfiddle.net/pravinasar/X325G/413/
0
Mike MillerSoftware EngineerAuthor Commented:
I think that's on the right track. However, I would need to determine a selected date's day of the week from 1 text box and essentially just limit the second text box to the same date.
0
Pravin AsarPrincipal Systems EngineerCommented:
You need to apply the event handler for second one, so as to enforce the specific date.

Just another suggestion, as soon as first date is picked, based the your date rule, set the second date, and disable any changes.

Or set min and max date range for the second datepicker

Clarify something for me,  so that we can define appropriate rule to restrict date

What is so special about march 26 sunday. Is this because you want to enforce rule to limit Sundays from current month only?
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Pravin AsarPrincipal Systems EngineerCommented:
I mean do you wish to set the rule to limit the second date to last sunday of the month, if user picks first date as last sunday of the month ?
0
Mike MillerSoftware EngineerAuthor Commented:
March 26 was just an example. I want to limit the 2nd textbox to the same date as the 1st text box any time that any Sunday is selected.

More examples:
TextBox1 - April 2nd, 2017 is selected by user...only April 2nd will be an option for the datepicker assigned to TextBox2
Textbox1 - May 14th, 2017 is selected by user...only May 14th will be an option for the datepicker assigned to TextBox2
Textbox1 - April 3rd, 2017 (Monday) is selected by user...no rules apply to the datepicker assigned to TextBox2
0
Pravin AsarPrincipal Systems EngineerCommented:
Got it.

Check the simplified code @

http://jsfiddle.net/pravinasar/X325G/443/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Pravin AsarPrincipal Systems EngineerCommented:
Thanks, You may add pop-up or dyamic note .

See update

http://jsfiddle.net/pravinasar/X325G/457/
0
Mike MillerSoftware EngineerAuthor Commented:
Ah very nice touch. I'm having trouble implementing it with some other things I'm doing. I've opened another question if you want to take a crack at it...

https://www.experts-exchange.com/questions/29011510/Combining-two-scripts.html
0
Pravin AsarPrincipal Systems EngineerCommented:
As of now, i am on the road.
0
Mike MillerSoftware EngineerAuthor Commented:
I ended up figuring it out. I was just leaving out a comma after the "beforeShowDay"
Thanks again!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Bootstrap

From novice to tech pro — start learning today.