How to show a search box inside a 'list' type of form field?
1 Answer
You need to load chosen plugin to style list box fields like this.
Load chosen plugin first in your form layout file so that it can add style to your select boxes
JHtml::_('formbehavior.chosen', 'select');
Add following class name to your form field (optional if you want to color it as mandatory field)
class="chzn-color-state"
To render the field on your form page:
<div class="control-group">
<div class="control-label">
<?php echo $this->form->getLabel('fieldname'); ?>
</div>
<div class="controls">
<?php echo $this->form->getInput('fieldname'); ?>
</div>
</div>
Note: The search box will be shown inside the listbox if there are 10 or more options inside it. See the below sample jQuery code that will be added by Joomla.
jQuery('select').chosen({"disable_search_threshold":10,
To override it, change your chosen loading code to following:
JHtml::_('formbehavior.chosen', 'select', null, array('disable_search_threshold'=>1));
-
I already have this included and it doesn't show the search box inside the list. May 16, 2015 at 16:51
-
What is the type of form field you are using in your form filter xml file?– NagarjunMay 16, 2015 at 17:31
-
list
the problem is not inside the filter. Inside the filter the list shows the search box. But when I show a similarlist
type of field in the form usinggetControlGroup
doesn't show the search box. May 16, 2015 at 17:36 -
I guess the number of options inside the listbox is less than 10. The search box automatically shows if its more than 10.– NagarjunMay 16, 2015 at 17:54
-