⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

[updated 24/11/2012] Dependent dropdown (library)



greyson
  • profile picture
  • Member

Posted 08 April 2018 - 06:00 AM

greetings vitor, my field bairro_id_bai is disabled, I'm a beginner and would love your help,

follow the code

 

 

function test()
{
$crud = new grocery_CRUD();
$crud->set_table('lideranca');
$crud->set_relation('municipio_id_mun', 'municipio', 'municipio');
$crud->set_relation('bairro_id_bai', 'bairro', 'bairro');
 
$this->load->library('gc_dependent_select');
 
$fields = array(
'municipio_id_mun' => array(// first dropdown name
'table_name' => 'municipio', // table of country
'title' => 'municipio', // country title
'relate' => null // the first dropdown hasn't a relation
),
'bairro_id_bai' => array(// second dropdown name
'table_name' => 'bairro', // table of state
'title' => 'bairro', // state title
'id_field' => 'bairro_id_bai', // table of state: primary key
'relate' => 'municipio_id_mun', // table of state:
'data-placeholder' => 'Select bairro' //dropdown's data-placeholder:
)
);
$config = array(
'main_table' => 'bairro',
'main_table_primary' => 'id_bai',
"url" => base_url() . __CLASS__ . '/' . __FUNCTION__ . '/',
);
$categories = new gc_dependent_select($crud, $fields, $config);
$js = $categories->get_js();
 
 
 
$output = $crud->render();
$output->output.= $js;
 
$this->_example_output($output);
}

greyson
  • profile picture
  • Member

Posted 08 April 2018 - 22:31 PM

field 2 inactive, someone could help


avi
  • profile picture
  • Member

Posted 09 April 2018 - 09:06 AM

Hi Guys,

 

It's a great library..

 

I have some problem, the second select list is updated but it's still disabled.. 

 

The select option is updated accordingly, however the JQuery Chosen is still disabled and it's not populated..

 

I wonder if someone has similar situation


priyanka
  • profile picture
  • Member

Posted 08 May 2018 - 05:25 AM

Hi, I am new to grocery crud library. For dependent dropdown, I used gc_dependent_select library. first dropdown work fine but second dropdown is disabled on page load as well as onchange firts dropdown. Please help me out

Please find the attached screenshot. URL: https://www.screencast.com/t/Xg88C9Th4byT

 

thanks

 


sandeep88
  • profile picture
  • Member

Posted 16 May 2018 - 06:31 AM

Hi, I'm a newbie to GC and I have managed to install it successfully. Now I'm trying to add the dependent select box with this library. I'm getting values in the country dropdown, but state and city dropdowns seem to be disabled. I think I'm having issues with including js files, please find attached files. Also, I have created the foreign key between tables country, state and city.

 

Pasting the controller function 

***********************************************************************

public function locs_management()
{
$crud = new grocery_CRUD();
$crud->set_theme('datatables');
$crud->set_table('locations');
$crud->set_relation('con_id','country','name');
$crud->set_relation('st_id','state','st_name');
$crud->set_relation('ct_id','city','ct_name');
$this->load->library('gc_dependent_select');
 
$fields = array(
 
// first field:
'con_id' => array( // first dropdown name
'table_name' => 'country', // table of country
'title' => 'name', // country title
'relate' => null // the first dropdown hasn't a relation
),
// second field
'st_id' => array( // second dropdown name
'table_name' => 'state', // table of state
'title' => 'st_name', // state title
'id_field' => 'id', // table of state: primary key
'relate' => 'con_id', // table of state:
'data-placeholder' => 'select state' //dropdown's data-placeholder:
 
),
// third field. same settings
'ct_id' => array(
'table_name' => 'city',
//'where' =>"post_code>'167'",  // string. It's an optional parameter.
//'order_by'=>"state_title DESC",  // string. It's an optional parameter.
'title' => 'id: {id} / city : {ct_name}',  // now you can use this format )))
'id_field' => 'city_id',
'relate' => 'st_id',
'data-placeholder' => 'select city'
)
);
 
$config = array(
'main_table' => 'locations',
'main_table_primary' => 'id',
"url" => base_url() . __CLASS__ . '/' . __FUNCTION__ . '/', //path to method
//'ajax_loader' => base_url() . 'ajax-loader.gif' // path to ajax-loader image. It's an optional parameter
//'segment_name' =>'Your_segment_name' // It's an optional parameter. by default "get_items"
);
//print_r ($crud);
        //print_r ($fields);
        //print_r ($config);
$categories = new gc_dependent_select($crud, $fields, $config);
$js = $categories->get_js();
$output = $crud->render();
$output->output.= $js;
$this->_example_output($output);
 
 
}

***********************************************************************

Thanks in advance.


ekobudi79
  • profile picture
  • Member

Posted 13 June 2018 - 05:43 AM

Hi Victor,

 

I have same problem like everyone, the first dropdown can be used, when i select one option the first dropdown the second dropdown still disabled. I am using GC 1.6 and your library version 1.5.

Please help me. Thanks.


kingwash
  • profile picture
  • Member

Posted 23 January 2019 - 11:29 AM

Helllo, i'm new to Grocery Crud. I need help on this dependent dropdown library.

 

I have downloaded (Gc_dependent_select.php)  but don't now how to use.

Please attach the database tables to your reply.

 

Thanks in advance


andreagam
  • profile picture
  • Member

Posted 25 February 2020 - 18:16 PM

Hi all and thanks Victor for this awesome library.
I just wanted to ask if it's possible to set a default selected value in the first dropdown.

Thanks for your help!

 

Andrew


kadejo
  • profile picture
  • Member

Posted 10 May 2020 - 20:27 PM

Hi all!

 

First of all I want to pay respects to [member='victor'] and of course to  [member='web-johnny'], I really appreciate your work and generosity open sourcing & sharing it.

 

I want to report that this library works perfectly on GC v1.6.3 too (as of May 2020), and also share two tips to ease its use:

 

1) In my case I had to add index.php, to the url parameter, as Victor already had answered in some other post in this same thread. 

 "url" => base_url() .'index.php/'. __CLASS__ . '/' . __FUNCTION__ . '/',

2) I think the next question is answered as follows, as I have two different dependent dropdowns on the same CRUD (linked to the same father dropdown, but for sure it is the same solution if they are cascaded dropdowns).

 

Hi Victor,

 

I have same problem like everyone, the first dropdown can be used, when i select one option the first dropdown the second dropdown still disabled. I am using GC 1.6 and your library version 1.5.

Please help me. Thanks.

 

For two (or more) dependent dropdowns segment_name parameter is mandatory, so you have to give it a different name for each dropdown (it is the last parameter so pay attention to add an ending ',' on previous line):

'segment_name' =>'second_select' 

Best regards,

 

Carlos