Changeset 2684


Ignore:
Timestamp:
Oct 8, 2008, 7:22:24 AM (16 years ago)
Author:
rub
Message:

jQuery Datepicker:
improve disabled elements on day and month lits

(disable day for short months)
(disable day and month for double selection)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/template/goto/include/datepicker.inc.tpl

    r2680 r2684  
    3636  }
    3737
    38   // Prevent selection of invalid dates through the select controls
    39   function pwg_check_date()
     38  // In order to desable element of list
     39  function pwg_disabled_selection()
    4040  {
    4141    array_date = $(linked_date).val().split('-');
    4242    y = array_date[0];
    4343    m = array_date[1];
    44     d = array_date[2];
     44
     45    // Init list
     46    $(day + " option").attr("disabled", "");
     47    $(month + " option").attr("disabled", "");
     48
     49    var daysInMonth = 32 - new Date(y, m - 1, 32).getDate();
     50    $(day + " option:gt(" + (daysInMonth) +")").attr("disabled", "disabled");
     51
     52    if ((min_linked_date != null) && ($(min_linked_date).datepicker("getDate") != null))
     53    {
     54      date_cmp = min_linked_date;
     55      op_cmp = "lt";
     56    }
     57    else if ((max_linked_date != null) && ($(max_linked_date).datepicker("getDate") != null))
     58    {
     59      date_cmp = max_linked_date;
     60      op_cmp = "gt";
     61    }
     62    else
     63    {
     64      date_cmp = null;
     65      op_cmp = null;
     66    }
     67
     68    if (op_cmp != null)
     69    {
     70      array_date = $(date_cmp).val().split('-');
     71      y_cmp = array_date[0];
     72      m_cmp = array_date[1];
     73      d_cmp = array_date[2];
     74     
     75      if (y == y_cmp)
     76      {
     77        $(month + " option:" + op_cmp + "(" + (m_cmp) +")").attr("disabled", "disabled");
     78        if (op_cmp ==  "lt")
     79        {
     80            $(month + " option:eq(" + (0) +")").attr("disabled", "");
     81        }
     82
     83        if (m == m_cmp)
     84        {
     85          $(day + " option:" + op_cmp + "(" + (d_cmp) +")").attr("disabled", "disabled");
     86          if (op_cmp ==  "lt")
     87          {
     88            $(day + " option:eq(" + (0) +")").attr("disabled", "");
     89          }
     90        }
     91      }
     92    }
     93  }
     94
     95  // Prevent selection of invalid dates through the select controls
     96  function pwg_check_date()
     97  {
     98    last_date = $(linked_date).val();
    4599
    46100    $(linked_date).val(pwg_get_fmt_datepicker(day, month, year));
     
    61115    if (cancel)
    62116    {
    63       $(year).val(y);
    64       $(month).val(m);
    65       $(day).val(d);
     117      array_date = last_date.split('-');
     118      $(year).val(array_date[0]);
     119      $(month).val(array_date[1]);
     120      $(day).val(array_date[2]);
    66121      // check again
    67122      pwg_check_date();
    68     }
    69     else
    70     {
    71       var daysInMonth = 32 - new Date($(year).val(), $(month).val() - 1, 32).getDate();
    72       $(day + " option").attr("disabled", "");
    73       $(day + " option:gt(" + (daysInMonth) +")").attr("disabled", "disabled");
    74123    }
    75124  }
     
    132181      });
    133182
    134     // In order to desable element of list
     183    // Check showed controls
     184    jQuery(day + ", " + month + ", " + year).focus(
     185      function ()
     186      {
     187        pwg_disabled_selection();
     188      });
     189
    135190    // In order to init linked input
    136191    pwg_check_date();
Note: See TracChangeset for help on using the changeset viewer.