Skip to content

Commit

Permalink
fixed: advanced search, filter once on > date element, submit, add 2n…
Browse files Browse the repository at this point in the history
…d filter on < same date element - gave error as 2nd js filter object not created/setup correctly
  • Loading branch information
pollen8 committed Feb 27, 2014
1 parent c738250 commit 69835c5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
12 changes: 12 additions & 0 deletions components/com_fabrik/models/list.php
Expand Up @@ -5841,6 +5841,7 @@ protected function &makeFilters($container = 'listform_1', $type = 'list', $id =
{
$aFilters = array();
$table = $this->getTable();
$formModel = $this->getFormModel();
$opts = new stdClass;
$opts->container = $container;
$opts->type = $type;
Expand Down Expand Up @@ -5879,6 +5880,7 @@ protected function &makeFilters($container = 'listform_1', $type = 'list', $id =
$o->filter .= '&nbsp;'
. JHTML::_('select.genericList', $opts, 'search-mode-advanced', "class='fabrik_filter'", 'value', 'text', $mode);
}

$o->name = 'all';
$o->label = $params->get('search-all-label', JText::_('COM_FABRIK_ALL'));
$aFilters[] = $o;
Expand Down Expand Up @@ -6173,6 +6175,7 @@ public function getAdvancedSearchRows()
$rows = array();
$first = false;
$elementModels = $this->getElements();
$input = JFactory::getApplication()->input;
list($fieldNames, $firstFilter) = $this->getAdvancedSearchElementList();
$prefix = 'fabrik___filter[list_' . $this->getRenderContext() . '][';
$type = '<input type="hidden" name="' . $prefix . 'search_type][]" value="advanced" />';
Expand Down Expand Up @@ -6260,6 +6263,15 @@ public function getAdvancedSearchRows()
$jsSel = JHTML::_('select.genericlist', $statements, $prefix . 'condition][]', 'class="inputbox" size="1" ', 'value', 'text', $jsSel);
$rows[] = array('join' => $join, 'element' => $key, 'condition' => $jsSel, 'filter' => $filter, 'type' => $type,
'grouped' => $grouped);

// 27/02/2014 - load up js filter code for existing elements - needed for date element
if ($input->get('layout') == '_advancedsearch')
{
$container = 'listform_' . $this->getRenderContext();
$input->set('counter', $counter);
$elementModel->filterJS(false, $container);
}

$counter++;
}
}
Expand Down
26 changes: 18 additions & 8 deletions plugins/fabrik_element/date/date.php
Expand Up @@ -802,7 +802,7 @@ public function calendar($value, $name, $id, $format = '%Y-%m-%d', $attribs = nu
/**
* get the options used for the date elements calendar
*
* @param int $id Repeat counter
* @param string $id HTML field id
*
* @return object ready for js encoding
*/
Expand Down Expand Up @@ -1300,6 +1300,7 @@ public function emptyFilterValue()
public function getFilter($counter = 0, $normal = true)
{
$params = $this->getParams();
$input = JFactory::getApplication()->input;
$listModel = $this->getListModel();
$table = $listModel->getTable();
$element = $this->getElement();
Expand Down Expand Up @@ -1453,7 +1454,14 @@ public function getFilter($counter = 0, $normal = true)

// Add wrapper div for list filter toggling
$return[] = '<div class="fabrik_filter_container">';
$return[] = $this->calendar($default, $v, $this->getFilterHtmlId(0), $format, $calOpts);

// Set counter in input to create the correct field id when in advanced search.
if (!$normal)
{
$input->set('counter', $counter);
}

$return[] = $this->calendar($default, $v, $this->getFilterHtmlId(0, $normal), $format, $calOpts);
$return[] = '</div>';
break;

Expand Down Expand Up @@ -1508,18 +1516,20 @@ public function getFilter($counter = 0, $normal = true)
/**
* Get filter HTML id
*
* @param int $range Which ranged filter we are getting
* @param int $range Which ranged filter we are getting
* @param bool $normal Is the filter a normal (true) or advanced filter
*
* @return string html filter id
* @return string HTML filter id
*/

protected function getFilterHtmlId($range)
protected function getFilterHtmlId($range, $normal = true)
{
$app = JFactory::getApplication();
$input = $app->input;
$counter = $input->get('counter', 0);
$suffix = $normal ? 'normal' : 'advanced';

return $this->getHTMLId() . '_filter_range_' . $range . '_' . $input->get('task') . '.' . $counter;
return $this->getHTMLId() . '_filter_range_' . $range . '_' . $input->get('task') . '.' . $counter . '.' . $suffix;
}

/**
Expand Down Expand Up @@ -2213,8 +2223,8 @@ public function filterJS($normal, $container)

$htmlid = $this->getHTMLId();
$params = $this->getParams();
$id = $this->getFilterHtmlId(0);
$id2 = $this->getFilterHtmlId(1);
$id = $this->getFilterHtmlId(0, $normal);
$id2 = $this->getFilterHtmlId(1, $normal);
$opts = new stdClass;
$opts->calendarSetup = $this->_CalendarJSOpts($id);
$opts->calendarSetup->ifFormat = $params->get('date_table_format', '%Y-%m-%d');
Expand Down

0 comments on commit 69835c5

Please sign in to comment.