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 2012/05/21 18:24:15 UTC

svn commit: r1341095 - in /myfaces/trinidad/branches/1.2.12.7.0-branch/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs: CoreFormat.js TrCollections.js

Author: gcrawford
Date: Mon May 21 16:24:14 2012
New Revision: 1341095

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

Thanks to Jing

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

Modified: myfaces/trinidad/branches/1.2.12.7.0-branch/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.7.0-branch/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js?rev=1341095&r1=1341094&r2=1341095&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.7.0-branch/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js (original)
+++ myfaces/trinidad/branches/1.2.12.7.0-branch/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js Mon May 21 16:24:14 2012
@@ -804,9 +804,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,
@@ -840,6 +840,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,
@@ -856,7 +884,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/branches/1.2.12.7.0-branch/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/TrCollections.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.7.0-branch/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/TrCollections.js?rev=1341095&r1=1341094&r2=1341095&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.7.0-branch/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/TrCollections.js (original)
+++ myfaces/trinidad/branches/1.2.12.7.0-branch/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/TrCollections.js Mon May 21 16:24:14 2012
@@ -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--;
         }
       }
     }