Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
php version added
Source Link
Liz.
  • 1.4k
  • 7
  • 24
  1. formname.xml

    <fieldset addfieldpath="/administrator/components/com_componentname/models/fields">
     <field name="id" type="text" readonly="true" class="readonly" default="0" description="JGLOBAL_FIELD_ID_DESC"/>
    
     <field name="cat_id_01" type="categoryList" onchange="loadSubcategory(1)" label="Category 1" description="Category">
        <option value="">Please select</option>
     </field>
    </fieldset>
    
  2. edit.php

    <?php echo $this->form->renderField('cat_id_01'); ?>
    
  3. How it appears on localhost: it displays as select-box with category options. This is how I want it to be displayed. php version: 7.0.0

  4. models/fields/categoryList.php

        JFormHelper::loadFieldClass('list');
    
                /**
                 * Supports an HTML select list of categories
                 *
                 * @since  1.6
                 */
                class JFormFieldCategoryList extends JFormFieldList
                {
                    /**
                     * The form field type.
                     *
                     * @var        string
                     * @since    1.6
                     */
                    protected $type = 'categoryList';
    
                    /**
                     * Method to get the field input markup.
                     *
                     * @return    string    The field input markup.
                     *
                     * @since    1.6
                     */
                    public function getOptions()
                    {
                        $categories[NULL] = 'Please Select';
                        $jinput = JFactory::getApplication()->input;
                        $db = JFactory::getDbo();
                        $query = 'SELECT id, title FROM `#__categories` WHERE parent_id IN (SELECT id from `#__categories` where title="'.$jinput->get('section').'")';
                        $rows = $db->setQuery($query)->loadObjectlist();
                        foreach ($rows as $row) {
                            $categories[$row->id] = $row->title;
                        }
    
                        return $categories;
                    }
    
                }
    
  5. How it appears on server: it displays as textbox and somehow the custom field is not working on server. php version: 7.0.17

    <div class="controls">
    <input type="text" name="jform[cat_id_01]" id="jform_cat_id_01" value="110" list="jform_cat_id_01_datalist" onchange="loadSubcategory(1)"><datalist id="jform_cat_id_01_datalist"></datalist>
    </div>
    
  6. Joomla version: 3.6.5

  1. formname.xml

    <fieldset addfieldpath="/administrator/components/com_componentname/models/fields">
     <field name="id" type="text" readonly="true" class="readonly" default="0" description="JGLOBAL_FIELD_ID_DESC"/>
    
     <field name="cat_id_01" type="categoryList" onchange="loadSubcategory(1)" label="Category 1" description="Category">
        <option value="">Please select</option>
     </field>
    </fieldset>
    
  2. edit.php

    <?php echo $this->form->renderField('cat_id_01'); ?>
    
  3. How it appears on localhost: it displays as select-box with category options. This is how I want it to be displayed.

  4. models/fields/categoryList.php

        JFormHelper::loadFieldClass('list');
    
                /**
                 * Supports an HTML select list of categories
                 *
                 * @since  1.6
                 */
                class JFormFieldCategoryList extends JFormFieldList
                {
                    /**
                     * The form field type.
                     *
                     * @var        string
                     * @since    1.6
                     */
                    protected $type = 'categoryList';
    
                    /**
                     * Method to get the field input markup.
                     *
                     * @return    string    The field input markup.
                     *
                     * @since    1.6
                     */
                    public function getOptions()
                    {
                        $categories[NULL] = 'Please Select';
                        $jinput = JFactory::getApplication()->input;
                        $db = JFactory::getDbo();
                        $query = 'SELECT id, title FROM `#__categories` WHERE parent_id IN (SELECT id from `#__categories` where title="'.$jinput->get('section').'")';
                        $rows = $db->setQuery($query)->loadObjectlist();
                        foreach ($rows as $row) {
                            $categories[$row->id] = $row->title;
                        }
    
                        return $categories;
                    }
    
                }
    
  5. How it appears on server: it displays as textbox and somehow the custom field is not working on server.

    <div class="controls">
    <input type="text" name="jform[cat_id_01]" id="jform_cat_id_01" value="110" list="jform_cat_id_01_datalist" onchange="loadSubcategory(1)"><datalist id="jform_cat_id_01_datalist"></datalist>
    </div>
    
  6. Joomla version: 3.6.5

  1. formname.xml

    <fieldset addfieldpath="/administrator/components/com_componentname/models/fields">
     <field name="id" type="text" readonly="true" class="readonly" default="0" description="JGLOBAL_FIELD_ID_DESC"/>
    
     <field name="cat_id_01" type="categoryList" onchange="loadSubcategory(1)" label="Category 1" description="Category">
        <option value="">Please select</option>
     </field>
    </fieldset>
    
  2. edit.php

    <?php echo $this->form->renderField('cat_id_01'); ?>
    
  3. How it appears on localhost: it displays as select-box with category options. This is how I want it to be displayed. php version: 7.0.0

  4. models/fields/categoryList.php

        JFormHelper::loadFieldClass('list');
    
                /**
                 * Supports an HTML select list of categories
                 *
                 * @since  1.6
                 */
                class JFormFieldCategoryList extends JFormFieldList
                {
                    /**
                     * The form field type.
                     *
                     * @var        string
                     * @since    1.6
                     */
                    protected $type = 'categoryList';
    
                    /**
                     * Method to get the field input markup.
                     *
                     * @return    string    The field input markup.
                     *
                     * @since    1.6
                     */
                    public function getOptions()
                    {
                        $categories[NULL] = 'Please Select';
                        $jinput = JFactory::getApplication()->input;
                        $db = JFactory::getDbo();
                        $query = 'SELECT id, title FROM `#__categories` WHERE parent_id IN (SELECT id from `#__categories` where title="'.$jinput->get('section').'")';
                        $rows = $db->setQuery($query)->loadObjectlist();
                        foreach ($rows as $row) {
                            $categories[$row->id] = $row->title;
                        }
    
                        return $categories;
                    }
    
                }
    
  5. How it appears on server: it displays as textbox and somehow the custom field is not working on server. php version: 7.0.17

    <div class="controls">
    <input type="text" name="jform[cat_id_01]" id="jform_cat_id_01" value="110" list="jform_cat_id_01_datalist" onchange="loadSubcategory(1)"><datalist id="jform_cat_id_01_datalist"></datalist>
    </div>
    
  6. Joomla version: 3.6.5

Source Link
Liz.
  • 1.4k
  • 7
  • 24

Custom form field not working on server

I created a custom component and in the form one custom field categoryList to list all categories dynamically. Following is the code:

  1. formname.xml

    <fieldset addfieldpath="/administrator/components/com_componentname/models/fields">
     <field name="id" type="text" readonly="true" class="readonly" default="0" description="JGLOBAL_FIELD_ID_DESC"/>
    
     <field name="cat_id_01" type="categoryList" onchange="loadSubcategory(1)" label="Category 1" description="Category">
        <option value="">Please select</option>
     </field>
    </fieldset>
    
  2. edit.php

    <?php echo $this->form->renderField('cat_id_01'); ?>
    
  3. How it appears on localhost: it displays as select-box with category options. This is how I want it to be displayed.

  4. models/fields/categoryList.php

        JFormHelper::loadFieldClass('list');
    
                /**
                 * Supports an HTML select list of categories
                 *
                 * @since  1.6
                 */
                class JFormFieldCategoryList extends JFormFieldList
                {
                    /**
                     * The form field type.
                     *
                     * @var        string
                     * @since    1.6
                     */
                    protected $type = 'categoryList';
    
                    /**
                     * Method to get the field input markup.
                     *
                     * @return    string    The field input markup.
                     *
                     * @since    1.6
                     */
                    public function getOptions()
                    {
                        $categories[NULL] = 'Please Select';
                        $jinput = JFactory::getApplication()->input;
                        $db = JFactory::getDbo();
                        $query = 'SELECT id, title FROM `#__categories` WHERE parent_id IN (SELECT id from `#__categories` where title="'.$jinput->get('section').'")';
                        $rows = $db->setQuery($query)->loadObjectlist();
                        foreach ($rows as $row) {
                            $categories[$row->id] = $row->title;
                        }
    
                        return $categories;
                    }
    
                }
    
  5. How it appears on server: it displays as textbox and somehow the custom field is not working on server.

    <div class="controls">
    <input type="text" name="jform[cat_id_01]" id="jform_cat_id_01" value="110" list="jform_cat_id_01_datalist" onchange="loadSubcategory(1)"><datalist id="jform_cat_id_01_datalist"></datalist>
    </div>
    
  6. Joomla version: 3.6.5

I want to display the field as selectbox on server as well.