diff options
Diffstat (limited to 'framework/Web')
-rw-r--r-- | framework/Web/Javascripts/source/prado/activecontrols/activecontrols3.js | 29 | ||||
-rw-r--r-- | framework/Web/UI/JuiControls/TJuiAutoComplete.php | 67 |
2 files changed, 82 insertions, 14 deletions
diff --git a/framework/Web/Javascripts/source/prado/activecontrols/activecontrols3.js b/framework/Web/Javascripts/source/prado/activecontrols/activecontrols3.js index 0a7511c1..5d4beef8 100644 --- a/framework/Web/Javascripts/source/prado/activecontrols/activecontrols3.js +++ b/framework/Web/Javascripts/source/prado/activecontrols/activecontrols3.js @@ -103,7 +103,12 @@ Prado.WebUI.TJuiAutoComplete = jQuery.klass(Prado.WebUI.TActiveTextBox, this.hasResults = false; jQuery.extend(this.options, { source: this.getUpdatedChoices.bind(this), - select: this.selectEntry.bind(this) + select: this.selectEntry.bind(this), + focus: function () { + return false; + }, + minLength: this.options.minLength, + frequency: this.options.frequency }); jQuery('#'+options.ID).autocomplete(this.options) .data( "ui-autocomplete")._renderItem = function( ul, item ) { @@ -131,22 +136,38 @@ Prado.WebUI.TJuiAutoComplete = jQuery.klass(Prado.WebUI.TActiveTextBox, getUpdatedChoices : function(request, callback) { - var params = new Array(request.term,"__TJuiAutoComplete_onSuggest__"); + var lastTerm = this.extractLastTerm(request.term); + var params = new Array(lastTerm, "__TJuiAutoComplete_onSuggest__"); var options = jQuery.extend(this.options, { 'autocompleteCallback' : callback }); Prado.Callback(this.options.EventTarget, params, this.onComplete.bind(this), this.options); }, + extractLastTerm: function(string) + { + var re = new RegExp("[" + this.options.Separators + "]"); + return string.split(re).pop().trim(); + }, + /** * Overrides parent implements, don't update if no results. */ - selectEntry: function(event, ui) - { + selectEntry: function(event, ui) { + var value = event.target.value; + var lastTerm = this.extractLastTerm(value); + + // strip (possibly) incomplete last part + var previousTerms = value.substr(0, value.length - lastTerm.length); + // and append selected value + ui.item.value = previousTerms + ui.item.value; + + //ui.item.value = event.target.value; var options = [ui.item.id, "__TJuiAutoComplete_onSuggestionSelected__"]; Prado.Callback(this.options.EventTarget, options, null, this.options); }, + onComplete : function(request, result) { var that = this; diff --git a/framework/Web/UI/JuiControls/TJuiAutoComplete.php b/framework/Web/UI/JuiControls/TJuiAutoComplete.php index 115969c5..f6663057 100644 --- a/framework/Web/UI/JuiControls/TJuiAutoComplete.php +++ b/framework/Web/UI/JuiControls/TJuiAutoComplete.php @@ -147,6 +147,57 @@ class TJuiAutoComplete extends TActiveTextBox implements INamingContainer, IJuiO return $this->getViewState('TextCssClass'); } + + /** + * @return string word or token separators (delimiters). + */ + public function getSeparator() + { + return $this->getViewState('separator', ''); + } + + /** + * @param string word or token separators (delimiters). + */ + public function setSeparator($value) + { + $this->setViewState('separator', TPropertyValue::ensureString($value), ''); + } + + /** + * @return float maximum delay (in seconds) before requesting a suggestion. + */ + public function getFrequency() + { + return $this->getViewState('frequency', 0.4); + } + + /** + * @param float maximum delay (in seconds) before requesting a suggestion. + * Default is 0.4. + */ + public function setFrequency($value) + { + $this->setViewState('frequency', TPropertyValue::ensureFloat($value), 0.4); + } + + /** + * @return integer minimum number of characters before requesting a suggestion. + */ + public function getMinChars() + { + return $this->getViewState('minChars',''); + } + + /** + * @param integer minimum number of characters before requesting a suggestion. + * Default is 1 + */ + public function setMinChars($value) + { + $this->setViewState('minChars', TPropertyValue::ensureInteger($value), 1); + } + /** * Raises the callback event. This method is overrides the parent implementation. * If {@link setAutoPostBack AutoPostBack} is enabled it will raise @@ -316,17 +367,11 @@ class TJuiAutoComplete extends TActiveTextBox implements INamingContainer, IJuiO */ protected function getPostBackOptions() { - //disallow page state update ? - //$this->getActiveControl()->getClientSide()->setEnablePageStateUpdate(false); $options = $this->getOptions()->toArray(); - /* - if(strlen($string = $this->getSeparator())) - { - $string = strtr($string,array('\t'=>"\t",'\n'=>"\n",'\r'=>"\r")); - $token = preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY); - $options['tokens'] = $token; - } - */ + + if(strlen($separator = $this->getSeparator())) + $options['Separators'] = $separator; + if($this->getAutoPostBack()) { $options = array_merge($options,parent::getPostBackOptions()); @@ -334,6 +379,8 @@ class TJuiAutoComplete extends TActiveTextBox implements INamingContainer, IJuiO } if(strlen($textCssClass = $this->getTextCssClass())) $options['textCssClass'] = $textCssClass; + $options['minLength'] = $this->getMinChars(); + $options['delay'] = $this->getFrequency()/1000.0; $options['appendTo'] = '#'.$this->getResultPanel()->getClientID(); $options['ID'] = $this->getClientID(); $options['EventTarget'] = $this->getUniqueID(); |