Skip to content

Commit

Permalink
changed/fixed cdd autocomplete filter in list view would not work or …
Browse files Browse the repository at this point in the history
…populate with data if observe element not also included in filter. default value was not being shown in autocomplete field after search
  • Loading branch information
pollen8 committed Oct 23, 2012
1 parent e557f61 commit 736cb5e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 7 deletions.
12 changes: 9 additions & 3 deletions media/com_fabrik/js/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,17 +252,23 @@ var FbAutocomplete = new Class({

});

var FbCddAutocomplete = new Class({
var FabCddAutocomplete = new Class({

Extends: FbAutocomplete,

search: function () {
search: function (e) {
var v = this.getInputElement().get('value');
if (v === '') {
this.element.value = '';
}
if (v !== this.searchText && v !== '') {
var key = document.id(this.options.observerid).get('value') + '.' + v;
var observer = document.id(this.options.observerid);
if (typeOf(observer) !== 'null') {
var key = observer.get('value') + '.' + v;
} else {
this.parent(e);
return;
}
this.positionMenu();
if (this.cache[key]) {
this.populateMenu(this.cache[key]);
Expand Down
26 changes: 24 additions & 2 deletions plugins/fabrik_element/cascadingdropdown/cascadingdropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ protected function getWatchElement()

protected function _buildQuery($data = array(), $incWhere = true, $opts = array())
{
$app = JFactory::getApplication();
$sig = isset($this->_autocomplete_where) ? $this->_autocomplete_where . '.' . $incWhere : $incWhere;
$sig .= '.' . serialize($opts);
$repeatCounter = JArrayHelper::getValue($opts, 'repeatCounter', 0);
Expand Down Expand Up @@ -580,7 +581,12 @@ protected function _buildQuery($data = array(), $incWhere = true, $opts = array(
{
// $$$ hugh - if watched element has no value, we have been selecting all rows from CDD table
// but should probably select none.
$whereval = '';

// Unless its a cdd autocomplete list filter - seems sensible to populate that with the values matching the search term
if ($app->input->get('method') !== 'autocomplete_options')
{
$whereval = '';
}
}
}
}
Expand Down Expand Up @@ -630,7 +636,7 @@ protected function _buildQuery($data = array(), $incWhere = true, $opts = array(

if (!empty($this->_autocomplete_where))
{
$where .= $where == '' ? ' AND ' . $this->_autocomplete_where : $this->_autocomplete_where;
$where .= $where !== '' ? ' AND ' . $this->_autocomplete_where : $this->_autocomplete_where;

}
$data = array_merge($data, $placeholders);
Expand Down Expand Up @@ -920,6 +926,22 @@ public function filterJS($normal, $container)
}
}

/**
* Get the field name for the joined tables' pk
*
* @since 3.0.7
*
* @return string
*/

protected function getJoinValueFieldName()
{
$params = $this->getParams();
$full = $params->get('cascadingdropdown_id');
$bits = explode('___', $full);
return JArrayHelper::getValue($bits, 1, $full);
}

/**
* Get the observed element's element model
*
Expand Down
24 changes: 22 additions & 2 deletions plugins/fabrik_element/databasejoin/databasejoin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1615,9 +1615,22 @@ protected function getJoinValueColumn()
$params = $this->getParams();
$join = $this->getJoin();
$db = FabrikWorker::getDbo();
return $db->quoteName($join->table_join_alias . '.' . $params->get('join_key_column'));
return $db->quoteName($join->table_join_alias . '.' . $this->getJoinValueFieldName());
}

/**
* Get the field name for the joined tables' pk
*
* @since 3.0.7
*
* @return string
*/

protected function getJoinValueFieldName()
{
$params = $this->getParams();
return $params->get('join_key_column');
}
/**
* Builds an array containing the filters value and condition
*
Expand Down Expand Up @@ -2261,7 +2274,14 @@ public static function cacheAutoCompleteOptions($elementModel, $search)
{
$join = $elementModel->getJoin()->table_join;
$opts = array();
$opts['label'] = !strstr($c, 'CONCAT') ? $join . '.' . $c : $c;
if (!strstr($c, 'CONCAT'))
{
$opts['label'] = strstr($c, '.') ? $c : $join . '.' . $c;
}
else
{
$opts['label'] = $c;
}
return parent::cacheAutoCompleteOptions($elementModel, $search, $opts);
}
// $$$ hugh - added 'autocomplete_how', currently just "starts_with" or "contains"
Expand Down

0 comments on commit 736cb5e

Please sign in to comment.