1

I am creating these dropdown lists in XML for plugin:

  • category multi-select dropdown,
  • subcategory multi-select dropdown

(All data comes from database table)

I want when I select the first category dropdown, then the second dropdown list should come under the selected category on first dropdown. Example:-

<field name="category- list"
       type="sql"
       default=""
       label="Category"
       sql_select="e.*"
       sql_from="#__category AS e"
       sql_group="category"
       sql_order="e.cat_id ASC"
       key_field="cat_id"
       value_field="category"
       multiple="true"/>

<field name="subcategory - list depend on category list"
       default=""
       type="sql"
       label="SubCategory"
       sql_select="e.*"
       sql_from="#__subcategory AS e"
       sql_group="subcategory"
       sql_order="e.subcat_id ASC"
       sql_filter="cat_id"
       key_field="subcat_id"
       value_field="subcategory"
       multiple="true" />

Please help me out how to achieve this.

Given below is table structure.

CREATE TABLE category (
    cat_id int(2) NOT NULL auto_increment,
    category varchar(25) NOT NULL default '',
    PRIMARY KEY (cat_id)
) 

CREATE TABLE subcategory (
    subcat_id int(3) NOT NULL AUTO_INCREMENT,
    cat_id int(2) NOT NULL DEFAULT '0',
    subcategory varchar(25) NOT NULL DEFAULT '',
    UNIQUE KEY subcat_id (subcat_id)
)
1

Your sql_filter value must match the name of the field it is referring to. Since you have cat_id in your subcategory table which is referring to id in category, name your parent field as cat_id.

Your category field with name cat_id.

<field name="cat_id"
   type="sql"
   default=""
   label="Category"
   sql_select="e.*"
   sql_from="#__category AS e"
   sql_group="category"
   sql_order="e.cat_id ASC"
   key_field="cat_id"
   value_field="category"/>

Sub category field can be same as what you have now.

<field name="subcategory"
   default=""
   type="sql"
   label="SubCategory"
   sql_select="e.*"
   sql_from="#__subcategory AS e"
   sql_group="subcategory"
   sql_order="e.subcat_id ASC"
   sql_filter="cat_id"
   key_field="subcat_id"
   value_field="subcategory"/>
  • I did the same as suggested by you but didn't get the desired result what i want. – Rakesh Singh Sep 13 '17 at 15:42
  • "Nagarjun" I need your input.How to achieve this?whatever you suggest but it doesn't work. I need your email Id. – Rakesh Singh Sep 20 '17 at 11:59
  • Please see documentation - docs.joomla.org/SQL_form_field_type Also try to remove multiple="true" parameter. – Nagarjun Sep 20 '17 at 16:57
  • Add some var_dump debug points in libraries\joomla\form\fields\sql.php and see what is the output of your setup. – Nagarjun Sep 22 '17 at 7:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.