I have a JHtml
custom filter populated by a JFormField
extended class. It is added in the view with the following code:
JHtmlSidebar::addFilter(
'- Select Height -',
'filter_height',
JHtml::_('select.options', $heightOptions, "value", "text", $this->state->get('filter.height'), true)
);
It works as intended but for some reason the filter will not display the default text (- Select Height -) but instead shows the "select an option" string (I've included another filter - coded the same way - in the screen shot to show what it should look like).
After some messing around I figured out that I could fix it by changing my database query in the JFormField
class. My original JFormField
class is as follows:
JFormHelper::loadFieldClass('list');
class JFormFieldHeight extends JFormFieldList
{
protected $type = 'Height';
public function getOptions()
{
$options = array();
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select("DISTINCT LEFT(a.description2, LOCATE('(', a.description2) - 1) AS height");
$query->from('#__cadcam_disc AS a');
$query->order("LEFT(a.description2, LOCATE('(', a.description2) - 1)");
$db->setQuery($query);
$options = $db->loadObjectList();
if ($db->getErrorNum()) {
JError::raiseWarning(500, $db->getErrorMsg());
}
return $options;
}
}
This code causes the problem but if I remove the LOCATE
function from the query it works fine. Obviously I need to keep the original query so this is not an option.
For info, the select box is loaded with the values in both cases including the default value but even selecting the default value will revert to the "select an option" string:
Any ideas what is going on here?