Author: pyaschenko
Date: 2008-05-13 11:32:24 -0400 (Tue, 13 May 2008)
New Revision: 8560
Modified:
trunk/samples/suggestionbox-sample/src/main/webapp/pages/index.jsp
trunk/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js
Log:
http://jira.jboss.com/jira/browse/RF-413
Modified: trunk/samples/suggestionbox-sample/src/main/webapp/pages/index.jsp
===================================================================
--- trunk/samples/suggestionbox-sample/src/main/webapp/pages/index.jsp 2008-05-13 15:22:28
UTC (rev 8559)
+++ trunk/samples/suggestionbox-sample/src/main/webapp/pages/index.jsp 2008-05-13 15:32:24
UTC (rev 8560)
@@ -41,12 +41,12 @@
<f:verbatim> </f:verbatim>
<h:panelGroup>
<h:inputText value="#{suggestionBox.property}"
id="text"/>
- <rich:suggestionbox id="suggestionBoxId" for="text"
+ <rich:suggestionbox id="suggestionBoxId" for="text"
tokens=","
rules="#{suggestionBox.rules}"
suggestionAction="#{suggestionBox.autocomplete}"
var="result"
fetchValue="#{result.text}"
first="#{suggestionBox.intFirst}"
- minChars="#{suggestionBox.minchars}"
+ minChars="0"
shadowOpacity="#{suggestionBox.shadowOpacity}"
border="#{suggestionBox.border}"
width="#{suggestionBox.width}"
Modified:
trunk/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js
===================================================================
---
trunk/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js 2008-05-13
15:22:28 UTC (rev 8559)
+++
trunk/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js 2008-05-13
15:32:24 UTC (rev 8560)
@@ -69,7 +69,7 @@
|| " ";
this.options.tokens = $A(options.tokens) || [];
this.options.frequency = this.options.frequency || 0.4;
- this.options.minChars = parseInt(this.options.minChars) || 1;
+ this.options.minChars = isNaN(this.options.minChars) ? 1 :
parseInt(this.options.minChars);
this.options.onShow = this.options.onShow ||
function(element, update, options) {
if (!update.style.position
@@ -259,6 +259,9 @@
var temp = this.update.cloneNode(true);
this.update.parentNode.removeChild(this.update);
this.update = temp;
+ this.update.component = this;
+ this["rich:destructor"] = "destroy";
+
document.body.insertBefore(this.update, document.body.firstChild);
this.initialized = true;
}
@@ -367,6 +370,7 @@
domEvt.screenY = event.screenY;
domEvt.shiftKey = event.shiftKey;
domEvt.which = event.which;
+ domEvt.rich = event.rich;
} catch(e) {
LOG.warn("Exception on clone event");
}
@@ -689,7 +693,7 @@
this.changed = false;
var oldValue = this.element.value;
- if (this.oldValue!=oldValue) {
+ if ((event.rich && event.rich.isCallSuggestion) ||
this.oldValue!=oldValue) {
this.startPosition = 0;
this.endPosition = oldValue.length;
if (this.options.tokens.length!=0) {
@@ -704,9 +708,9 @@
if (this.options.usingSuggestObjects) this.updateItems(oldValue);
}
- if (this.getToken().length >= this.options.minChars) {
+ if ((event.rich && event.rich.ignoreMinChars) || this.getToken().length
>= this.options.minChars) {
LOG.debug("Call data for update choices");
- if ((event.keyCode == Event.KEY_DOWN || this.oldValue != oldValue) &&
oldValue.length > 0) {
+ if (event.keyCode == Event.KEY_DOWN || this.oldValue != oldValue) {
this.startIndicator();
this.getUpdatedChoices(event);
}
@@ -718,6 +722,45 @@
this.observerHandle = null;
},
+ callSuggestion: function (ignoreMinChars)
+ {
+ if (!this.hasFocus)
+ {
+ this.element.focus();
+ Richfaces.Selection.setCaretTo(this.element, this.element.value.length);
+ }
+ var domEvt = {};
+ domEvt.target = this.element;
+ domEvt.type = "keydown";
+ domEvt.altKey = false;
+ domEvt.clientX = 0;
+ domEvt.clientY = 0;
+ domEvt.ctrlKey = false;
+ domEvt.keyCode = 40;
+ domEvt.pageX = 0;
+ domEvt.pageY = 0;
+ domEvt.screenX = 0;
+ domEvt.screenY = 0;
+ domEvt.shiftKey = false;
+ domEvt.which = 40;
+ domEvt.rich = {"isCallSuggestion":true, "ignoreMinChars":
ignoreMinChars};
+
+ this.onKeyDownListener(domEvt);
+ },
+
+ getSelectedItems: function()
+ {
+ var result = new Array();
+ if (this.options.usingSuggestObjects)
+ {
+ for (var i=0;i<this.selectedItems.length; i++)
+ {
+ if (this.selectedItems[i].object ) result.push(this.selectedItems[i].object);
+ }
+ }
+ return result;
+ },
+
updateItems:function (newValue)
{
this.isSelectedItemsUpdated = false;
@@ -867,8 +910,16 @@
this.onsubmitFunction = new Function(onsubmit+';return
true;').bind(this.element);
}
+ this.update.component = this;
+ this["rich:destructor"] = "destroy";
+
return this;
},
+
+ destroy: function ()
+ {
+ this.update.component = null;
+ },
getUpdatedChoices: function(event) {
this.options.parameters[this.options.param] = this.getToken();