[richfaces-svn-commits] JBoss Rich Faces SVN: r5192 - trunk/sandbox/ui/combobox/src/main/resources/org/richfaces/renderkit/html/scripts.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Tue Jan 8 12:57:00 EST 2008


Author: vmolotkov
Date: 2008-01-08 12:56:59 -0500 (Tue, 08 Jan 2008)
New Revision: 5192

Modified:
   trunk/sandbox/ui/combobox/src/main/resources/org/richfaces/renderkit/html/scripts/combobox.js
Log:
component corrected

Modified: trunk/sandbox/ui/combobox/src/main/resources/org/richfaces/renderkit/html/scripts/combobox.js
===================================================================
--- trunk/sandbox/ui/combobox/src/main/resources/org/richfaces/renderkit/html/scripts/combobox.js	2008-01-08 17:49:04 UTC (rev 5191)
+++ trunk/sandbox/ui/combobox/src/main/resources/org/richfaces/renderkit/html/scripts/combobox.js	2008-01-08 17:56:59 UTC (rev 5192)
@@ -78,10 +78,10 @@
 	},
 	
 	valueHandler : function(event) {
+		this.field.focus();
 		this.setValue(true);
 		
 		this.comboList.hide();
-		this.field.focus();
 	},
 	
 	setValue : function(toSetOnly) {
@@ -142,9 +142,13 @@
 	
 	dataUpdating : function(event) {
 		if (Richfaces.ComboBox.SPECIAL_KEYS.indexOf(event.keyCode) == -1) {
+			this.comboList.hide();
 			if (this.filterNewValue) {
 				this.comboList.dataFilter(this.field.value);
-				this.comboList.show();
+				if (this.comboList.getItems() && this.comboList.getItems().length != 0) {
+					var isSearchSuccessful = true;
+					this.comboList.show();					
+				}
 			} else {
 				if (!this.comboList.visible()) {
 					this.comboList.show();
@@ -156,7 +160,7 @@
 				}
 			}
 			
-			if (event.keyCode != Event.KEY_BACKSPACE ) {
+			if ((event.keyCode != Event.KEY_BACKSPACE) && isSearchSuccessful) {
 				this.setValue();
 			}
 		}
@@ -244,25 +248,33 @@
 		this.listParent.style.width = this.width;
 		
 		var height = this.height;
-		if (!this.height) {
-			var item = this.list.childNodes[0];
-			if (item) {
-				//FIXME
-				this.listParent.style.visibility = "hidden";
-				this.listParent.show();
-								
-				var itemHeight = item.offsetHeight;
-				
-				this.listParent.hide();
-				this.listParent.style.visibility = "visible";
-				
-				var rowsAmount = this.getItems().length;
-				var k = this.defaultRowsAmount;
-				if (rowsAmount < this.defaultRowsAmount) {
-					k = rowsAmount;
-				}
-				height = k * itemHeight;
+		
+		var currentItemsHeight;
+		var rowsAmount;
+		var item = this.getItems()[0];
+		if (item) {
+			//FIXME
+			this.listParent.style.visibility = "hidden";
+			this.listParent.show();
+			
+			var itemHeight = item.offsetHeight;
+			
+			this.listParent.hide();
+			this.listParent.style.visibility = "visible";
+			rowsAmount = this.getItems().length;
+			currentItemsHeight = itemHeight * rowsAmount;
+		}
+		
+		if (this.height && (this.height < currentItemsHeight)) {
+			if (this.height < currentItemsHeight) {
+				height = currentItemsHeight;
 			}
+		} else {
+			if (rowsAmount < this.defaultRowsAmount) {
+				height = currentItemsHeight;
+			} else {
+				height = itemHeight * this.defaultRowsAmount;
+			}
 		}
 		this.listParent.style.height = height;
 	},
@@ -338,6 +350,9 @@
 	
 	moveSelectedItem : function(event) {
 		var item = this.selectedItem;
+		if (!this.selectedItem) {
+			return;
+		}
 		if (event.keyCode == Event.KEY_UP) {
 			var prevItem = item.previousSibling;
 			if (prevItem) {
@@ -358,9 +373,9 @@
 	},
 	
 	resetState : function() {
-		if (this.selectedItem) {
-			this.normalizeItem(this.selectedItem);			
-		}
+		var tempList = this.list.cloneNode(false);
+		this.listParent.replaceChild(tempList, this.listParent.firstChild);
+		this.list = this.listParent.firstChild;
 		this.selectedItem = null;
 		this.isList = false;
 	},
@@ -390,13 +405,9 @@
 	},
 	
 	createNewList : function(items) {
-		//TODO: write code for IE
-		var tempList = this.list.cloneNode(false);
-		this.listParent.removeChild(this.listParent.firstChild);
-		
-		tempList.innerHTML = items.join("");
-		this.listParent.appendChild(tempList);
-		this.list = this.listParent.firstChild;
+		//FIX for FF
+		this.list.innerHTML = items.join("");
+		//this.listParent.appendChild(tempList);
 	},
 	
 	createItem : function(text, className) {
@@ -427,7 +438,7 @@
 } 
 
 Richfaces.ComboBox.SPECIAL_KEYS = [
-	Event.KEY_RETURN, Event.KEY_UP, Event.KEY_DOWN
+	Event.KEY_RETURN, Event.KEY_UP, Event.KEY_DOWN, Event.KEY_RIGHT, Event.KEY_LEFT 
 ]
 
 Richfaces.ComboBoxList.CLASSES = {




More information about the richfaces-svn-commits mailing list