⚠ 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)



amipax
  • profile picture
  • Member

Posted 30 April 2013 - 23:42 PM

 hello buddies,

  I have a problem with a simple dependent dropdown menu, when i select a commune, i notice on my firebug console that the request is sending "/get_items/id_sector/224" there aren't sector ids that correspond with that id, it should request "get_items/idComuna/224".


the code    

 


function display_grid(){


      $data['titulo']= "Tabla propiedades";
      $data['contenido']= "admin_propiedades_grid";
      $crud = new grocery_CRUD();
     // $crud->set_subject('Propiedades');
      $crud->set_table('propiedad');
      $crud->set_relation('idComuna','comunas','nombre');
      $crud->set_relation('id_sector','sectores','nombre');
      
      
      $this->load->library('gc_dependent_select');
      //Settings
    $fields = array(

      //primer campo
      'idComuna'   => array(
      'table_name' => 'comunas',
      'title'      => 'nombre',
      'relate'     =>  null

      ),

       //segundo campo
      'id_sector'  => array(
      'table_name' => 'sectores',
      'title'      => 'nombre',
      'id_field'   => 'id_sector',
      'relate'     => 'idComuna',
      'data-placeholder' =>' Seleccione sector'
      )
      );
          
     $config = array(
      'main_table'  => 'propiedad',
      'main_table_primary' => 'id_propiedad',
      "url" => base_url().__CLASS__ .'/'. __FUNCTION__ .'/',
      'ajax_loader' => base_url().'img/ajax-loader.gif'
      );
      
      

      $crud->display_as('id_propiedad','Id');
      $crud->display_as('superficie','Superficie (casa/terreno)');
      $crud->display_as('banos','Baños');
      $crud->display_as('ano','Año Construcción');
      $crud->display_as('idComuna','Comuna');
      $crud->display_as('id_sector','Sector');
      
      
      
      $crud->columns('id_propiedad','operacion','tipo','superficie','valor','sector','comuna','estado');
      
      $crud->field_type('tipo','enum', array('cabañas','casas','departamento','local comercial','oficinas'));
      $crud->field_type('codigo','invisible');
      $crud->field_type('fecha_creacion','invisible');
      $crud->field_type('fecha_actualizacion','invisible');
      $crud->field_type('creado_por','invisible');
      $crud->field_type('actualizado_por','invisible');

      $crud->unset_texteditor('descripcion');

      //render crud + dropdown
      $todo = new gc_dependent_select($crud, $fields, $config);

      /*$output = $todo->render();
      $data['tablecrud'] = $output;*/
      $js = $todo->get_js();
      $output = $crud->render();
      $output->output.= $js;
      $data['tablecrud'] = $output;
      $this->load->view('admin_plantilla',$data);
 

davidoster
  • profile picture
  • Member

Posted 01 May 2013 - 05:39 AM

change this 'id_field'   => 'id_sector',


amipax
  • profile picture
  • Member

Posted 01 May 2013 - 18:28 PM

hi, 

id_sector is the primary key in the sectores table, it should be correct.  even so i tried other values with no result at all. 

 

 is "get_items/id_sector/224" looking for match in the Sectores table ?  if so it should find a match in the idComuna field from the sectores table.  


victor
  • profile picture
  • Member

Posted 01 May 2013 - 18:44 PM

1)amipax, do you use index.php in url?

for example project/index.php/function/method?

if so you need set 'url' => base_url() . 'index.php/' . __CLASS__. '/' . __FUNCTION__ . '/',

 

2) case two :

you need to use the strtolower function 

'url' => base_url() . strtolower(__CLASS__) . '/' . strtolower(__FUNCTION__) . '/',

3)case 3:

you need to use both advices

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


amipax
  • profile picture
  • Member

Posted 01 May 2013 - 18:55 PM

 hi Victor,

 

  Spasibo,  I don't use index.php 

 

 i just notice on my url : http://localhost/corretaje/admin/propiedades/display_grid/add , since i'm working on what would be the back-end.

 

  => "admin" that doesn't appear on my error console,

 

so I fixed my url settings => "url" => base_url().'admin'.'/'.strtolower(__CLASS__) .'/'. strtolower(__FUNCTION__).'/',

 

and ir works like a charm  :)

 

 Thanks a lot,! 


victor
  • profile picture
  • Member

Posted 01 May 2013 - 19:04 PM

you can use the other library:

/topic/1561-simple-dependant-dropdown-extension/

but you should read that topic because there are a few version of the library.


Robert
  • profile picture
  • Member

Posted 06 June 2013 - 12:51 PM

hi, i have a problem with the library maiby someone can help me ..

 

i used for code :

 

function test()
{

$crud = new grocery_CRUD();
$crud->set_table('masini');
$crud->set_relation('marca_id', 'marca_masini', 'marca');
$crud->set_relation('model_id', 'model_masini', 'model');

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

$fields = array(
'marca_id' => array(     
  'table_name' => 'marca_masini',  
  'title' => 'country_title',   
  'relate' => null      
),
'model_id' => array(         
'table_name' => 'model_masini',        
'title' => 'model',          
'id_field' => 'id',          
'relate' => 'marca_id',         
'data-placeholder' => 'Select Subcategory'     
)
);

$config = array(
'main_table' => 'masini',
'main_table_primary' => 'id',
"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);
}

  // output + load site template
function _example_output($output = null){


$this->load->view ('include/header');
    $this->load->view('our_template.php',$output);
    $this->load->view ('include/footer');
    }

 

 

and DB tables are :

 

image.png


victor
  • profile picture
  • Member

Posted 08 June 2013 - 09:04 AM

what is your problem? please, more info


Robert
  • profile picture
  • Member

Posted 09 June 2013 - 17:11 PM

Well it lets me select the model but then i cant select the brand of the car .. i looked on the forum but cant figure out what i did wrong .. it has to me like this if i select lets say audi to have some audi models and so on .. 


victor
  • profile picture
  • Member

Posted 09 June 2013 - 17:52 PM

I'd like to see your database scheme to solve your problem.

Robert
  • profile picture
  • Member

Posted 09 June 2013 - 18:44 PM

i upload it here . i use this DB and the code i posted about .. 


Robert
  • profile picture
  • Member

Posted 10 June 2013 - 08:51 AM

anyone ?


Rodrigo Furtado
  • profile picture
  • Member

Posted 11 June 2013 - 14:49 PM

Hello!

 

Congrats for the library! It's awesome!

 

I would like to know if there is a way to use set_relation_n_n already ?

 

I'm programming a real estate website and they have a database with all the states, cities and neighborhood from my country.

What they want is that the user can register his interest to buy/rent a place in all the neighborhoods he likes from a given city.

In the website current state I know only how to make the user choose one and only one neighborhood after the guy selects his city. How could I use the set_relation_n_n like it usually works (being able to select multiple options) but with the power of your library to show only the ones from the city the user selected ?

Thanks!


victor
  • profile picture
  • Member

Posted 11 June 2013 - 15:32 PM

the library doesn't support this functionality. But I think You can change the core of the library to make it work.


Rodrigo Furtado
  • profile picture
  • Member

Posted 11 June 2013 - 16:46 PM

I offer $40 to anyone who can do it :) If not ready by tomorrow I ll do it myself thursday.


victor
  • profile picture
  • Member

Posted 11 June 2013 - 22:48 PM

sorry. I no time to make that) if you find a solution let us to know )

victor
  • profile picture
  • Member

Posted 11 June 2013 - 22:49 PM

sorry. I have no time to make that) if you find a solution let us to know )

Robert
  • profile picture
  • Member

Posted 12 June 2013 - 05:28 AM

victor did you find out what i did wrong in the DB ?


victor
  • profile picture
  • Member

Posted 12 June 2013 - 15:09 PM

Sorry Robert, Not yet. Tomorrow I'll take a look at your code.  


Suad Ara
  • profile picture
  • Member

Posted 22 June 2013 - 19:57 PM

Hi, I'm a newbie in Grocery_Crud. I'm using this library and it's working great in adding but when I try to edit something I get this error:

 

Fatal error: Cannot use object of type stdClass as array in \application\libraries\gc_dependent_select.php on line 105

 

Can anyone help please?

 

Thanks in advance