Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. Using datePicker to disable dates already selected

Using datePicker to disable dates already selected

Scheduled Pinned Locked Moved JavaScript
databasejavascripthtmlcomquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xnaLearner
    wrote on last edited by
    #1

    hey guys..So I am using datepicker http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerStartEnd.htmlto select start and end dates.I have the controller coded so that if the user attempts to select a date from the calendar (which is already stored for them-from a previous selection) it will not add it to the DB. I also have the weekends blocked out so they cant be used (done using http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerCustomCellRender.html) E.g say the user has previously selected fri 14th and added it to the DB, if they try to make a new record selecting from thur 13th to mon 17th- only thur 13, and mon 17th will be added to the DB. As fri 14th was previously added and 15 and 16th are weekendsone using the following code:

    [HttpPost] public ActionResult listHolidays(Holiday holiday, int? PersonId, string HolidayDate, string endDate, string AlreadyExists)
    { DateTime startDates = Convert.ToDateTime(HolidayDate);
    DateTime endDates = Convert.ToDateTime(endDate);

    while (startDates <= endDates)
    {
    if (startDates.DayOfWeek != DayOfWeek.Saturday && startDates.DayOfWeek != DayOfWeek.Sunday)
    {
    ViewBag.CantDuplicateHolidays = String.IsNullOrEmpty(AlreadyExists) ? "date" : "";
    var dates = from d in db.Holidays
    where d.HolidayDate == startDates && d.PersonId == PersonId
    select d;

    // <= 0..so if it does not already exist
    if (dates.Count() <= 0)
    {
    Holiday holiday1 = new Holiday();
    holiday1.PersonId = PersonId.Value;
    holiday1.HolidayDate = startDates;

    db.Holidays.AddObject(holiday1);
    db.SaveChanges();
    //say start date is 10. AddDays(1) will make it 11 then return it to startDates in 'startDates' = startdates,
    //but doesnt chage the value of startdates = 'startdates'
    }

    }

    startDates = startDates.AddDays(1);
    }

    return RedirectToAction("Index");
    }

    --------------- my view

    Date.format = 'dd/m/yyy';
    $("#HolidayDate").addClass('date-pick');
    $("#endDate").addClass('date-pick');
    //$('.date-pick').datePicker//({dateFormat: 'dd-mm-yy'}).val();

    // clickInput: true

    $(function () {
    //3 methods below dont allow user to select weekends
    $('.date-pick').datePicker(
    {
    createButton: false,
    renderCallback: function ($td, thisDate, month, year) {
    if (thisDate.isWeekend()) {
    $td.addClass('weekend');
    $td.addClass('disabled');
    }

    }
    }
    )

    .bind('click',
    function () {
    $(this).dpDisplay();
    this.blur();
    return false;
    }
    )

    .bind('dateSelected',
    function (e, selectedDate, $td) {

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups