From 69835c5a1176cd3bfedb59ec1e42df9d6007ffb3 Mon Sep 17 00:00:00 2001 From: pollen8 Date: Thu, 27 Feb 2014 19:53:41 +0100 Subject: [PATCH] fixed: advanced search, filter once on > date element, submit, add 2nd filter on < same date element - gave error as 2nd js filter object not created/setup correctly --- components/com_fabrik/models/list.php | 12 ++++++++++++ plugins/fabrik_element/date/date.php | 26 ++++++++++++++++++-------- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/components/com_fabrik/models/list.php b/components/com_fabrik/models/list.php index 42692b7f8c0..4b855ccc9cb 100644 --- a/components/com_fabrik/models/list.php +++ b/components/com_fabrik/models/list.php @@ -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; @@ -5879,6 +5880,7 @@ protected function &makeFilters($container = 'listform_1', $type = 'list', $id = $o->filter .= ' ' . 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; @@ -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 = ''; @@ -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++; } } diff --git a/plugins/fabrik_element/date/date.php b/plugins/fabrik_element/date/date.php index d905ef4b9f7..215924da86c 100644 --- a/plugins/fabrik_element/date/date.php +++ b/plugins/fabrik_element/date/date.php @@ -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 */ @@ -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(); @@ -1453,7 +1454,14 @@ public function getFilter($counter = 0, $normal = true) // Add wrapper div for list filter toggling $return[] = '
'; - $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[] = '
'; break; @@ -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; } /** @@ -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');