Skip to content

Commit

Permalink
changed: db join autocomplete. If no matched record found field reset…
Browse files Browse the repository at this point in the history
… to empty - enables the use of not-empty validations
  • Loading branch information
pollen8 committed May 8, 2013
1 parent ed37fd3 commit 366a55b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion media/com_fabrik/js/autocomplete-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion media/com_fabrik/js/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ var FbAutocomplete = new Class({
url: 'index.php',
max: 10,
onSelection: Class.empty,
autoLoadSingleResult: true
autoLoadSingleResult: true,
storeMatchedResultsOnly: false // Only store a value if selected from picklist
},

initialize: function (element, options) {
this.matchedResult = false;
this.setOptions(options);
this.options.labelelement = typeOf(document.id(element + '-auto-complete')) === "null" ? document.getElement(element + '-auto-complete') : document.id(element + '-auto-complete');
this.cache = {};
Expand All @@ -41,9 +43,20 @@ var FbAutocomplete = new Class({
this.search(e);
}.bind(this));

this.getInputElement().addEvent('blur', function (e) {
if (this.options.storeMatchedResultsOnly) {
if (!this.matchedResult) {
if (!(this.data.length === 1 && this.options.autoLoadSingleResult)) {
this.element.value = '';
}
}
}
}.bind(this));

},

search: function (e) {
this.matchedResult = false;
if (e.key === 'tab') {
this.closeMenu();
return;
Expand Down Expand Up @@ -126,6 +139,7 @@ var FbAutocomplete = new Class({
var ul = this.menu.getElement('ul');
ul.empty();
if (data.length === 1 && this.options.autoLoadSingleResult) {
this.matchedResult = true;
this.element.value = data[0].value;
this.fireEvent('selection', [this, this.element.value]);
}
Expand All @@ -148,6 +162,8 @@ var FbAutocomplete = new Class({
if (typeOf(li) !== 'null') {
this.getInputElement().value = li.get('text');
this.element.value = li.getProperty('data-value');

this.matchedResult = true;
this.closeMenu();
this.fireEvent('selection', [this, this.element.value]);
// $$$ hugh - need to fire change event, in case it's something like a join element
Expand Down
4 changes: 3 additions & 1 deletion plugins/fabrik_element/databasejoin/databasejoin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2286,7 +2286,9 @@ public function elementJavascript($repeatCounter)
$id = $this->getHTMLId($repeatCounter);
if ($this->getParams()->get('database_join_display_type') == 'auto-complete')
{
FabrikHelperHTML::autoComplete($id, $this->getElement()->id, 'databasejoin');
$autoOpts = array();
$autoOpts['storeMatchedResultsOnly'] = true;
FabrikHelperHTML::autoComplete($id, $this->getElement()->id, 'databasejoin', $autoOpts);
}
$opts = $this->elementJavascriptOpts($repeatCounter);
return array('FbDatabasejoin', $id, $opts);
Expand Down

0 comments on commit 366a55b

Please sign in to comment.