⚠ 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

Trying to implement the library for interdependent select lists



MarkusD

MarkusD
  • profile picture
  • Member

Posted 13 December 2012 - 15:48 PM

Hello,

I am trying to do just as it is written on the library, and I have an identical case, countries, states and cities and another table, so it should be straightforward, yet .. I am not coming on :wacko:

I have the 3 tables:

countries,

regions

towns



then I have another table called attributes which has, as foreign keys, the primary keys of each of these 3 tables, id_country, id_region, id_town

Then the names of the dropdowns are:

countries, for countries

regions, for regions

towns for cities

And also the tables for countries states and cites are interrelated the same way that it is shown in the library.

I have then the following code:


$crud->set_relation('id_country', 'country', 'name_country');
$crud->set_relation('id_region', 'regions', 'name_region');
$crud->set_relation('id_town', 'towns', 'name_town');


$this->load->library('gc_dependent_select');



$fields = array(

// first field:
'countries' => array( // first dropdown name
'table_name' => 'countries', // table of country
'title' => 'name_country', // country title
'relate' => null // the first dropdown hasn't a relation
),

// second field
'regions' => array( // second dropdown name
'table_name' => 'regions', // table of state
'title' => 'name_region', // state title
'id_field' => 'id_region', // table of state: primary key
'relate' => 'id_country', // table of state: id_pais es la foreign key de paises
'data-placeholder' => 'select state' //dropdown's data-placeholder:

),


// third field. same settings
'towns' => array(
'table_name' => 'towns',
'order_by'=>"name_town DESC", // string. It's an optional parameter.
'title' => 'id: {id_town} / city : {name_town}', // now you can use this format )))
'id_field' => 'id_town',
'relate' => 'id_region',
'data-placeholder' => 'select city'
)
);



$config = array(
'main_table' => 'atributes',
'main_table_primary' => 'id_atribut',
#"url" => base_url() . __CLASS__ . '/' . __FUNCTION__ . '/', 'atributos_Copy'/'atributs_code'
"url" =>base_url() . '__atributos_Copia__' .'/' .'__atributos_codigo__'. '/',
);


$categories = new gc_dependent_select($crud, $fields, $config);


//$output = $categories->render();

// the second method:
$js = $categories->get_js();

$output->output.= $js;



I am not sure if I have interpreted the sample correctly, but what happens is that when I click on the pencil for example to update the data, it takes 3 minutes to open the panel and the select lists are not interconnected, if I move one, the other doesnt notice, also the text editor is gone, there is no formatting headers etc, so the page is very much screwed, I dont know if I have to replace the "main_table" and "table_name" by the actual name of MY tables, but I did that and made no difference.

victor

victor
  • profile picture
  • Member

Posted 13 December 2012 - 21:21 PM

Can you draw a scheme of your case?(tables structure)

victor

victor
  • profile picture
  • Member

Posted 13 December 2012 - 21:29 PM

as I see you have controller name 'atributos_Copia', haven't you?

victor

victor
  • profile picture
  • Member

Posted 13 December 2012 - 21:33 PM

In your case : "url" =>base_url() . 'atributos_Copia' .'/' .'atributos_codigo'. '/',
In my example __CLASS__ - is class name.
You can read more info about this syntax here : http://php.net/manual/en/language.constants.predefined.php

MarkusD

MarkusD
  • profile picture
  • Member

Posted 14 December 2012 - 09:17 AM

[quote name='victor' timestamp='1355433697' post='4711']
Can you draw a scheme of your case?(tables structure)
[/quote]

MarkusD

MarkusD
  • profile picture
  • Member

Posted 14 December 2012 - 09:29 AM

.