Author: francois.b
Date: 2010-05-19 18:45:04 +0200 (Wed, 19 May 2010)
New Revision: 29532

Modified:
   
plugins/sfUnobstrusiveWidgetPlugin/trunk/data/assets/js/jquery/uo_widget_form_date_picker.jquery.js
Log:
[sfUnobstrusiveWidgetPlugin] fixed date picker to be able to use it with any 
date format

Modified: 
plugins/sfUnobstrusiveWidgetPlugin/trunk/data/assets/js/jquery/uo_widget_form_date_picker.jquery.js
===================================================================
--- 
plugins/sfUnobstrusiveWidgetPlugin/trunk/data/assets/js/jquery/uo_widget_form_date_picker.jquery.js
 2010-05-19 14:03:27 UTC (rev 29531)
+++ 
plugins/sfUnobstrusiveWidgetPlugin/trunk/data/assets/js/jquery/uo_widget_form_date_picker.jquery.js
 2010-05-19 16:45:04 UTC (rev 29532)
@@ -152,6 +152,7 @@
 
       /**
        * Prepare to show a date picker linked to 3 controls
+       * beforeshow
        */
       function readLinked(input, inst)
       {
@@ -169,8 +170,31 @@
         
         if (objects)
         {
-          $(this).val(objects.month.val() + '/' + objects.day.val() + '/' + 
objects.year.val());
+          var
+              currentDay   = objects.day.val(),
+              currentMonth = objects.month.val(),
+              currentYear  = objects.year.val();
 
+            if (!currentDay)
+            {
+              currentDay = $('option[value!=""]:first', 
'#jst_registration_born_at_day').attr('value');
+            }
+            
+            if (!currentMonth)
+            {
+              currentMonth = $('option[value!=""]:first', 
'#jst_registration_born_at_month').attr('value');
+            }
+            
+            if (!currentYear)
+            {
+              currentYear = $('option[value!=""]:first', 
'#jst_registration_born_at_year').attr('value');
+            }
+
+          if (currentDay && currentMonth && currentYear)
+          {
+            $(input).datepicker('setDate', new Date(currentYear, currentMonth 
-1, currentDay));
+          }
+
           if ($('option', objects.year).length > 0)
           {
             minDate = new Date(($('option:eq(0)', objects.year).attr('value') 
!= '') ? $('option:eq(0)', objects.year).attr('value') : $('option:eq(1)', 
objects.year).attr('value'), 1 - 1, 1);
@@ -224,24 +248,9 @@
 
         if (objects)
         {
-          indexForDay   = $.datepicker._defaults.dateFormat.indexOf('dd');
-          indexForMonth = $.datepicker._defaults.dateFormat.indexOf('mm');
-          indexForYear  = $.datepicker._defaults.dateFormat.indexOf('yy');
-
-          var offsetForYear;
-          if (objects.year.attr('maxlength'))
-          {
-            offsetForYear = objects.year.attr('maxlength');
-          }
-          else
-          {
-            var lastYear = objects.year.find('option:last').attr('value');
-            offsetForYear = lastYear.length;
-          }
-
-          objects.month.val(dateText.substring(indexForMonth, 
indexForMonth+2));
-          objects.day.val(dateText.substring(indexForDay, indexForDay+2));
-          objects.year.val(dateText.substring(indexForYear, 
indexForYear+offsetForYear));
+          objects.month.val(inst.selectedMonth + 1);
+          objects.day.val(inst.selectedDay);
+          objects.year.val(inst.selectedYear);
         }
       }
 
@@ -261,8 +270,8 @@
         {
           objects = $rangeWidgets;
         }
-
-        $('#'+baseId).val(objects.month.val() + '/' + objects.day.val() + '/' 
+ objects.year.val());
+        
+        $(input).datepicker('setDate', new Date(objects.year.val(), 
objects.month.val() -1, objects.day.val()));
       }
 
       /**

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.

Reply via email to