Permalink
Browse files

changed: db join autocomplete. If no matched record found field reset…

… to empty - enables the use of not-empty validations
  • Loading branch information...
1 parent ed37fd3 commit 366a55bcd4614d283963e3aaede248bb7c11945f @pollen8 pollen8 committed May 8, 2013

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -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 = {};
@@ -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;
@@ -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]);
}
@@ -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
@@ -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);

0 comments on commit 366a55b

Please sign in to comment.