[richfaces-svn-commits] JBoss Rich Faces SVN: r5095 - in trunk/sandbox/ui/combobox/src/main: templates and 1 other directory.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Fri Dec 28 14:50:41 EST 2007


Author: vmolotkov
Date: 2007-12-28 14:50:41 -0500 (Fri, 28 Dec 2007)
New Revision: 5095

Added:
   trunk/sandbox/ui/combobox/src/main/resources/org/richfaces/renderkit/html/scripts/comboboxUtils.js
Modified:
   trunk/sandbox/ui/combobox/src/main/resources/org/richfaces/renderkit/html/scripts/combobox.js
   trunk/sandbox/ui/combobox/src/main/templates/combobox.jspx
Log:
filtering of data was added

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	2007-12-28 19:35:03 UTC (rev 5094)
+++ trunk/sandbox/ui/combobox/src/main/resources/org/richfaces/renderkit/html/scripts/combobox.js	2007-12-28 19:50:41 UTC (rev 5095)
@@ -1,8 +1,12 @@
 if (!window.Richfaces) window.Richfaces = {};
 Richfaces.ComboBox = Class.create();
+
 Richfaces.ComboBox.prototype = {
 	
-	initialize: function(combobox, listId, fieldId, buttonId, classes, listWidth, listHeight, itemsText) {
+	initialize: function(combobox, listId, fieldId, buttonId, classes, listWidth, listHeight, itemsText, directInputSuggestions, filterNewValue) {
+		this.directInputSuggestions = directInputSuggestions;
+		this.filterNewValue = filterNewValue;
+		
 		this.combobox = $(combobox); 
 		this.comboList = new Richfaces.ComboBoxList(listId, classes, listWidth, listHeight, itemsText);
 		this.field = $(fieldId);
@@ -45,13 +49,48 @@
 		this.comboList.hide();
 	},
 	
-	setValue : function() {
-		this.field.value = this.comboList.selectedItem.innerHTML;
+	setValue : function(toSetOnly) {
+		var value = this.comboList.selectedItem.innerHTML;
+		if (toSetOnly) {
+			this.field.value = value;
+		} else {
+			if (this.directInputSuggestions) {
+				var startInd = this.field.value.length; 
+				var endInd = value.length;
+				this.field.value = value;
+				Richfaces.ComboBox.textboxSelect(this.field, startInd, endInd);
+			} 
+		}
 	},
 	
 	keyboardManager : function(event) {
-		if ((event.keyCode == Event.KEY_UP) || (event.keyCode == Event.KEY_DOWN)) {
+		/*if ((event.keyCode == Event.KEY_UP) || (event.keyCode == Event.KEY_DOWN)) {
 			this.comboList.moveSelectedItem(event);
+		} else if (event.keyCode == Event.KEY_RETURN) {
+			this.setValue(true);
+			this.comboList.hide();
+			Event.stop(event);
+		} else if (event.keyCode == Event.KEY_BACKSPACE) {
+			this.comboList.hide();
+		}*/
+		
+		switch (event.keyCode) {
+			case Event.KEY_RETURN : 
+				this.setValue(true);
+				this.comboList.hide();
+				Event.stop(event);
+				break;
+			case Event.KEY_BACKSPACE : 
+				this.comboList.hide();
+				break;
+			case Event.KEY_DOWN : 
+				this.comboList.moveSelectedItem(event);
+				break;
+			case Event.KEY_UP :
+				this.comboList.moveSelectedItem(event);
+				break; 
+			default : 
+				//this.dataUpdating(event);
 		}
 	},
 	
@@ -60,12 +99,18 @@
 	},
 	
 	dataUpdating : function(event) {
-		//this.comboList.setItems(this.comboList.dataFilter(this.field.value));
-		if ((event.keyCode != Event.KEY_UP) && (event.keyCode != Event.KEY_DOWN)) {
-			this.comboList.dataFilter(this.field.value);
-			this.comboList.show();
+		if (Richfaces.ComboBox.SPECIAL_KEYS.indexOf(event.keyCode) == -1) {
+			if (this.filterNewValue) {
+				this.comboList.dataFilter(this.field.value);
+				this.comboList.show();
+			} else {
+				//TODO
+			}
+			
+			if (event.keyCode != Event.KEY_BACKSPACE ) {
+				this.setValue();
+			}
 		}
-		this.setValue();
 	}
 };
 
@@ -81,6 +126,7 @@
 		//this.items = this.getItems();
 		
 		this.classes = classes;
+		
 		this.selectedItem = null;
 		
 		this.setSize(width, height);
@@ -238,6 +284,21 @@
    return {left: x, top: y};
 }
 
+Richfaces.ComboBox.textboxSelect = function(oTextbox, iStart, iEnd) {
+   if (Prototype.Browser.IE) {
+       var oRange = oTextbox.createTextRange();
+       oRange.moveStart("character", iStart);
+       oRange.moveEnd("character", -oTextbox.value.length + iEnd);      
+       oRange.select();                                              
+   } else if (Prototype.Browser.Gecko) {
+       oTextbox.setSelectionRange(iStart, iEnd);
+   }                    
+} 
+
+Richfaces.ComboBox.SPECIAL_KEYS = [
+	Event.KEY_RETURN, Event.KEY_UP, Event.KEY_DOWN
+]
+
 Richfaces.ComboBoxList.CLASSES = {
 	ITEM : {NORMAL : "rich-combobox-item rich-combobox-item-normal", SELECTED : "rich-combobox-item rich-combobox-item-selected"},
 	LIST : {}

Added: trunk/sandbox/ui/combobox/src/main/resources/org/richfaces/renderkit/html/scripts/comboboxUtils.js
===================================================================

Modified: trunk/sandbox/ui/combobox/src/main/templates/combobox.jspx
===================================================================
--- trunk/sandbox/ui/combobox/src/main/templates/combobox.jspx	2007-12-28 19:35:03 UTC (rev 5094)
+++ trunk/sandbox/ui/combobox/src/main/templates/combobox.jspx	2007-12-28 19:50:41 UTC (rev 5095)
@@ -14,6 +14,7 @@
 	<f:resource name="org.richfaces.renderkit.images.ComboBoxImage" var="combo_img" /> 
 	<h:scripts>
 			new org.ajax4jsf.javascript.PrototypeScript(),
+			scripts/comboboxUtils.js,
 			scripts/combobox.js
 	</h:scripts>
 	
@@ -36,6 +37,6 @@
 							   "list#{clientId}", 
 							   "comboboxField#{clientId}", 
 							   "comboboxButton#{clientId}", Richfaces.ComboBoxList.CLASSES, 100, 150,
-							   #{this:getItemsTextAsJSArray(context, component)});
+							   #{this:getItemsTextAsJSArray(context, component)}, true, true);
 	</script>
 </f:root>	
\ No newline at end of file




More information about the richfaces-svn-commits mailing list