You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by gc...@apache.org on 2011/01/12 01:26:59 UTC

svn commit: r1057956 - in /myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs: CoreFormat.js TrCollections.js

Author: gcrawford
Date: Wed Jan 12 00:26:59 2011
New Revision: 1057956

URL: http://svn.apache.org/viewvc?rev=1057956&view=rev
Log:
TRINIDAD-1979 Issue with client side DateRestrictionValidator 

Thanks to Jing Wu for the patch

Modified:
    myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js
    myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/TrCollections.js

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js?rev=1057956&r1=1057955&r2=1057956&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js Wed Jan 12 00:26:59 2011
@@ -809,9 +809,9 @@ TrDateRestrictionValidator.prototype.get
   
   //if needed, remove the submitted values, which are invalid, to display only the valid ones
   if(this._weekdaysValue)
-    TrCollections.removeValuesFromArray(this._weekdaysValue, allWeekdays);
+    this._removeDisabledValues(this._weekdaysValue, allWeekdays);
   if(this._monthValue)
-  TrCollections.removeValuesFromArray(this._monthValue, allMonth);
+    this._removeDisabledValues(this._monthValue, allMonth);
   
   return _returnHints(
     this._messages,
@@ -845,6 +845,34 @@ TrDateRestrictionValidator.prototype._tr
     return values;
   }
 }
+
+/**
+ * For all values in allValueArray, check if it is disabled by looking up
+ * map disabledValueMap, if so, remove it from allValueArray
+ */
+TrDateRestrictionValidator.prototype._removeDisabledValues = function(
+  disabledValueMap,
+  allValueArray
+  )
+{
+  if(disabledValueMap && allValueArray)
+  {
+    for (i=0; i<allValueArray.length; i++)
+    {
+      if(disabledValueMap[allValueArray[i].toLowerCase()] != undefined)
+      {
+        allValueArray.splice(i,1);
+
+        // the element originally at index i is removed, and 
+        // we now have a new element at index i, thus we need
+        // to stay on the same position to check whether we
+        // need to remove it.
+        i--;
+      }
+    }
+  }
+}
+
 TrDateRestrictionValidator.prototype.validate  = function(
   value,
   label,
@@ -861,7 +889,7 @@ TrDateRestrictionValidator.prototype.val
       if(weekDaysArray[i].toLowerCase() == dayString)
       {
         var allWeekdays = ['mon','tue','wed','thu','fri','sat','sun'];
-        TrCollections.removeValuesFromArray(this._weekdaysValue, allWeekdays);
+        this._removeDisabledValues(this._weekdaysValue, allWeekdays);
         var days = _trToString(this._translate(allWeekdays, this._translatedWeekdaysMap, converter.getLocaleSymbols().getWeekdays()));
 
         var facesMessage;

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/TrCollections.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/TrCollections.js?rev=1057956&r1=1057955&r2=1057956&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/TrCollections.js (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/TrCollections.js Wed Jan 12 00:26:59 2011
@@ -43,6 +43,12 @@ TrCollections.removeValuesFromArray = fu
         if(allValues[j].toLowerCase() == value.toLowerCase())
         {
           allValues.splice(j,1);
+
+          // the element originally at index j is removed, and 
+          // we now have a new element at index j, thus we need
+          // to stay on the same position to check whether we
+          // need to remove it.
+          j--;
         }
       }
     }