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



tlc033

tlc033
  • profile picture
  • Member

Posted 26 November 2012 - 09:26 AM

Hi. Victor. I update a new version v 1.2.0 & from GC github last update but it not work.
My controler is like this:
function programs_management()
{
$crud = new grocery_CRUD();

$crud->set_table('programs');
$crud->set_subject('program');
$crud->columns('program_id','country_id','channel_id','program_name','description','start_time','end_time','type_categ','type_id','logo_program');
$crud->display_as('country_id','Country')
->display_as('channel_id','Channel')
->display_as('program_name','Name program')
->display_as('logo_program','Base image/video')
->display_as('type_categ','Type category')
->display_as('type_id','Type program');
$crud->unset_columns('description');

$crud->fields('country_id','channel_id','program_name','logo_program','description','start_time','end_time','type_categ','type_id','status');
$crud->change_field_type('type_id', 'enum', array('Live','Reluare','Deleted'));
$crud->required_fields('country_id','channel_id','program_name','start_time','end_time','type_categ');

$crud->set_relation('country_id','countries','country_name');
$crud->set_relation('channel_id','channels','channel_name');
$crud->set_relation('type_categ','type_categ','type_categ');

$crud->set_field_upload('logo_program','assets/uploads/files');
$crud->add_action('Add images', base_url().'img/admin/icons/add_photo.png', '','ui-icon-image',array($this,'add_image_program'));


// settings
$config_view = array(
'table_name'=>'programs',
'related_table'=>'channels',
'sort_field'=>'channel_id',
'categories_primary_key'=>'channel_id',
'related_title_field'=>'channel_name',

'first_url' => base_url().__CLASS__.'/'.__FUNCTION__,
'segment_name' => 'channel',
'style' => 'height:24px; width: 200px;',
'text'=>array('all_rows'=>' All channels ')
);

$fields = array(

// first field:
'country_id' => array( // first dropdown name
'table_name' => 'countries', // table of country
'title' => 'country_name', // country title
'relate' => null // the first dropdown hasn't a relation
),
// second field
'channel_id' => array( // second dropdown name
'table_name' => 'channels', // table of channels
'title' => 'channel_name', // channel name
'id_field' => 'channel_id', // table of channels: primary key
'relate' => 'country_id', // table of country:
'data-placeholder' => 'select channel' //dropdown's data-placeholder:
)
);

$config = array(
'main_table' => 'programs',
'main_table_primary' => 'program_id',
"url" => base_url() . __CLASS__ . '/' . __FUNCTION__ . '/',
'ajax_loader' => base_url() . 'img/ajax-loader.gif' // path to ajax-loader image. It's an optional parameter
);
$categories_view = new grocery_crud_categories($crud,$config_view);
$dropdown = $categories_view->get_dropdown();
$categories = new gc_dependent_select(&$crud, $fields, $config);

// first method:
$output = $categories->render();
$output->output = $dropdown . $output->output;

// the second method:
//$js = $categories->get_js();
//$output = $crud->render();
//$output->output.= $js;
//$output = $crud->render();
$this->_admin_output($output);
}

For add:
[img]http://s9.postimage.org/q3oxdc73j/image.png[/img]

For edit:
[img]http://s11.postimage.org/7qntvsqc3/image.png[/img]

I declare this in function __construct()
$this->load->library('grocery_crud_categories');
$this->load->library('gc_dependent_select');

victor

victor
  • profile picture
  • Member

Posted 26 November 2012 - 09:59 AM

send me your database dump. I'll try help you, but later only. I'm busy now.

kenshicu

kenshicu
  • profile picture
  • Member

Posted 28 November 2012 - 21:56 PM

victor, the library fantastic, thanks :)
should be part of grocery crud, by default, very useful. :ph34r:

victor

victor
  • profile picture
  • Member

Posted 28 November 2012 - 23:27 PM

Thanks :).
But this version of my library works perfectly for GC 1.3.3. I'll update the library when will be realized a stable version of the GC 1.4.

MarkusD

MarkusD
  • profile picture
  • Member

Posted 04 December 2012 - 19:08 PM

Thank you very much, extraordinary job! I have not tried yet but it is an amazing achievement, precisely what so many of us were looking for! I will try it tomorrow and I hope I do well.

congratulations!

victor

victor
  • profile picture
  • Member

Posted 04 December 2012 - 19:10 PM

If you will have a question you can type it here :)

kenshicu

kenshicu
  • profile picture
  • Member

Posted 05 December 2012 - 13:17 PM

how I can make a combo, dependent of 2 or more combos together?

davidoster

davidoster
  • profile picture
  • Member

Posted 06 December 2012 - 10:27 AM

Hello again.
I have a situation where the very last select, which depends from the previous, needs to be multiselect and not a simple select.
On the documentation in order to make a multiselect you need to specify an array with the values that holds, but since this is done via the library, this cannot be done via php.
So we need somehow to change the last select to a multiselect, if it is not already, and load the correct values.
I can get the correct values from my model and output them as a json response.

Any ideas?
Thank you.

victor

victor
  • profile picture
  • Member

Posted 06 December 2012 - 10:49 AM

Do you want to use the set_relation_n_n method ?
can you draw a scheme?

davidoster

davidoster
  • profile picture
  • Member

Posted 06 December 2012 - 11:03 AM

I already use the gc_dependent_library like this. Will it work if I make use of the set_relation_n_n? I don't think so to be honest!



$this->load->library('gc_dependent_select');
$fields = array(
'activities_id' => array(
'table_name' => 'activities',
'title' => '{year} {description}',
'relate' => null),
'groups_id' => array(
'table_name' => 'groups',
'title' => '{day} {hour} {description}',
'id_field' => 'id',
'relate' => 'activities_id',
'data-placeholder' => 'some greek text :P'
)
);
$config = array(
'main_table' => 'payments',
'main_table_primary' => 'id',
'url' => base_url() . 'index.php/' . strtolower(__CLASS__) . '/' . strtolower(__FUNCTION__) . '/',
'ajax_loader' => base_url() . 'style/images/'. 'ajax-loader.gif'
);
$categories = new gc_dependent_select(&$this->grocery_crud, $fields, $config);
$js = $categories->get_js();

$output = $this->grocery_crud->render($data);
$output->output .= $js;
$this->_main_output($output);

victor

victor
  • profile picture
  • Member

Posted 06 December 2012 - 11:58 AM

My library realy uses the callback_field for each field. I'm busy now. I can have a look at your case later.

davidoster

davidoster
  • profile picture
  • Member

Posted 06 December 2012 - 13:22 PM

Victor take your time!
Thank you for your help!

kenshicu

kenshicu
  • profile picture
  • Member

Posted 11 December 2012 - 00:42 AM

how I can make a dropdown dependent of two-parent dropdown?

victor

victor
  • profile picture
  • Member

Posted 11 December 2012 - 07:24 AM

My library doesn't supports this functionality.

jhonKey

jhonKey
  • profile picture
  • Member

Posted 13 December 2012 - 10:15 AM

code runs fine in save process, but an error in the editing process,
can you help me please ?

MarkusD

MarkusD
  • profile picture
  • Member

Posted 13 December 2012 - 11:00 AM

.

davidoster

davidoster
  • profile picture
  • Member

Posted 13 December 2012 - 11:06 AM

You don't concatenate,

"url" => base_url() . __CLASS__ . '/' . __FUNCTION__ . '/', 'myController . '/' . method_that_takes_me_to_the_administration_panel'


'myController . '/' .
[quote name='MarkusD' timestamp='1355396445' post='4695']
Hello,

I am in the process of implementing the library, and I think I have done alright until the end where I am not sure how I should write the path because I am not familiar with this syntax of __CLASS__ AND __FUNCTION__

as you describe it here:


"url" => base_url() . __CLASS__ . '/' . __FUNCTION__ . '/', path to method


I have done this:


"url" => base_url() . __CLASS__ . '/' . __FUNCTION__ . '/', 'myController'/'method_that_takes_me_to_the_administration_panel'


but I must be doing something really wrong because I get an error that says:


Message: Division by zero

Filename: controllers/my_controller.php

and I get 3 repeated times the display of my data to edit, add, delete, and if I click on the pencil or on add it is a mess, so definitively I am not writing the url right or I dont know ..
[/quote]

victor

victor
  • profile picture
  • Member

Posted 13 December 2012 - 19:53 PM

[quote name='jhonKey' timestamp='1355393743' post='4694']
code runs fine in save process, but an error in the editing process,
can you help me please ?
[/quote]
When did you download the latest version of grocery crud?
May be it your problem /topic/1087-updated-24112012-dependent-dropdown-library/page__st__60#entry4441

victor

victor
  • profile picture
  • Member

Posted 13 December 2012 - 20:56 PM

David Oster, thanks for help :D. Is problem solved?


[quote name='David Oster' timestamp='1354791799' post='4608']
I already use the gc_dependent_library like this. Will it work if I make use of the set_relation_n_n? I don't think so to be honest!



$this->load->library('gc_dependent_select');
$fields = array(
'activities_id' => array(
'table_name' => 'activities',
'title' => '{year} {description}',
'relate' => null),
'groups_id' => array(
'table_name' => 'groups',
'title' => '{day} {hour} {description}',
'id_field' => 'id',
'relate' => 'activities_id',
'data-placeholder' => 'some greek text :P'
)
);
$config = array(
'main_table' => 'payments',
'main_table_primary' => 'id',
'url' => base_url() . 'index.php/' . strtolower(__CLASS__) . '/' . strtolower(__FUNCTION__) . '/',
'ajax_loader' => base_url() . 'style/images/'. 'ajax-loader.gif'
);
$categories = new gc_dependent_select(&$this->grocery_crud, $fields, $config);
$js = $categories->get_js();

$output = $this->grocery_crud->render($data);
$output->output .= $js;
$this->_main_output($output);

[/quote]

davidoster

davidoster
  • profile picture
  • Member

Posted 13 December 2012 - 21:01 PM

[quote name='victor' timestamp='1355432187' post='4706']
David Oster, thanks for help :D. Is problem solved?
[/quote]

You welcome! ;) No I haven't, not yet at least! It is a low priority problem!