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



Paul Savostin
  • profile picture
  • Member

Posted 15 July 2015 - 22:00 PM

Dear Victor, thanks a lot for this library. It works fine but I don't understand how to recieve the second dropdown data.
I get an html aswer from my config url (base_url() . __CLASS__./_MYFUNCTION), but how must be it structured? as a json array or like a select>option ?

Thanks for your help!
Best regards.
 

Hi! This is just URL to function where you are using this dependent dropdown library, no more!


Sebastián
  • profile picture
  • Member

Posted 21 July 2015 - 14:40 PM

Hi! This is just URL to function where you are using this dependent dropdown library, no more!

Sorry buy I don't undestand.
If every time I chose an item for the first dropdown, it try to load the 'url'=>base_url().'index.php/'.__CLASS__.'/'.__METHOD__.'/'

getting the values for the second dropdown, BUT what's the code for that METHOD?
just an html output like <option value="1">Same value</option> or what?

 


Cindy Lorena
  • profile picture
  • Member

Posted 10 August 2015 - 20:34 PM

hello as I can do because I only load dependent lists the first table.


Cindy Lorena
  • profile picture
  • Member

Posted 11 August 2015 - 16:15 PM

for difficult cases use KaBaDaBrA's code.
Maybe in the next version I'll try make this functionality.

hello victor could make an example of crud grocery master detail


geekygirl
  • profile picture
  • Member

Posted 22 September 2015 - 21:37 PM

Is this plugin compatible with GC 1.5.2 and does it still work?


victor
  • profile picture
  • Member

Posted 25 September 2015 - 12:16 PM

Is this plugin compatible with GC 1.5.2 and does it still work?

I did not check that.


Prince Hector
  • profile picture
  • Member

Posted 18 November 2015 - 05:33 AM

I have a product Table , there is category and sub category field. So I want to change sub categiries depends on category . So I write the code below

 

$fields = array(
                'Sub_Categry' => array(
                'table_name' => 'sub_category',
                'title' => 'Sub Category',
                'id_field' => 'sub_cat_id',
                'relate' => 'category_id',
                'data-placeholder' => 'select Sub category'

                )
            );

 

$config = array(
                'main_table' => 'category',
                'main_table_primary' => 'category_id',
                "url" => base_url() . __CLASS__ . '/' . __FUNCTION__ . '/',
                'ajax_loader' => base_url() . 'ajax-loader.gif',
                'segment_name' =>'Your_segment_name'
            );

 

$categories2 = new gc_dependent_select($crud, $fields, $config);
            $js2 = $categories2->get_js();

            $output = $crud->render();
            $output->output.= $js2;

            $this->_example_output($output);

 

 

But it didnt work. Where did I wrong ? Can any one help me plzzz ??


Prince Hector
  • profile picture
  • Member

Posted 18 November 2015 - 05:35 AM

I have a product Table , there is category and sub category field. So I want to change sub categiries depends on category . So I write the code below

 

$fields = array(
                'Sub_Categry' => array(
                'table_name' => 'sub_category',
                'title' => 'Sub Category',
                'id_field' => 'sub_cat_id',
                'relate' => 'category_id',
                'data-placeholder' => 'select Sub category'

                )
            );

 

$config = array(
                'main_table' => 'category',
                'main_table_primary' => 'category_id',
                "url" => base_url() . __CLASS__ . '/' . __FUNCTION__ . '/',
                'ajax_loader' => base_url() . 'ajax-loader.gif',
                'segment_name' =>'Your_segment_name'
            );

 

$categories2 = new gc_dependent_select($crud, $fields, $config);
            $js2 = $categories2->get_js();

            $output = $crud->render();
            $output->output.= $js2;

            $this->_example_output($output);

 

 

But it didnt work. Where did I wrong ? Can any one help me plzzz ??


ljegou
  • profile picture
  • Member

Posted 20 February 2016 - 15:39 PM

Too bad this useful library doesn't work with current GC version :-(


Mohamed Abukhatwa
  • profile picture
  • Member

Posted 03 March 2016 - 23:37 PM

Thank you for the Library but mr.grocery CRUD Hero wouldn't work when i tested it. once i select the country dropdown the state and the city dropdown never show up.

P.S i used ot


mohdzaid
  • profile picture
  • Member

Posted 28 April 2016 - 21:15 PM

Hi Victor, whats your recommendation if I need to filter few records for the first dropdown. I have an existing table with over 10K records.

 

 

Table structure.

 

Vendor Master:

Id, name, type (enum), blah1, blah2, blah3

 

The third field "type" has 4 different values (Cement Supplier, Bricks Supplier, another type1, another type2)

 

for some reason I need to show the records type = Cement Supplier in the first dropdown.

 

Is there any workaround / approach to achieve this.

 

 

 

Thanks,

Mohammad


pramin100
  • profile picture
  • Member

Posted 12 May 2016 - 06:17 AM

Dear Victor,

 

Thank for wonder work. But in my case, it is working in localhost but when i upload in live server it is not working. Please help.

 

Pramin

 


Neeraj Singh
  • profile picture
  • Member

Posted 31 May 2016 - 20:42 PM

Hi Victor,

 

 

Thanks for this useful library. But, the Dependent Drop-down not working with latest GC 'assets'. I have tried this with old version 'assets' and new version 'assets'. I am using latest GC models (Grocery_crud_model.php: 1.5.4) and library (Grocery_CRUD.php: 1.5.4) in both (CI latest CodeIgniter 3.0.6).

 

Here is result:

 

GC 1.5.4 and latest 'assets' has working ajax and getting data properly but not populating drop-down. The select box still lock after getting ajax data.

Error_First.png

 

GC 1.5.4 and old 'assets' has working ajax and getting data properly and populating in drop-down, working fine

 

Working_Fine.png

 

 

Will you plz help me to fix this problem, I am stuck in a project. Your help would be much appreciated Victor :)

 

Download Code for test: https://drive.google.com/open?id=0B2Jr4ZrDD_hFdDlCRGhNMjZuY00

 

-Best

Neeraj Singh


Php Power Arts
  • profile picture
  • Member

Posted 04 June 2016 - 18:04 PM

you are genius , thanks for this great lib :) , better to making it on github and add more simple examples 


Php Power Arts
  • profile picture
  • Member

Posted 05 June 2016 - 11:58 AM

 

Please help , its not work for me this is my code , i just find the second dropdown menu disabled and not changed any idea ?

 


function index()
    {
        $this->load->library('grocery_CRUD');
        if (!$this->ion_auth->logged_in()) {
            // redirect them to the login page
            redirect('user/login', 'refresh');
        } else {


            $crud = new Grocery_CRUD();
            $crud->set_table('venues');
            $crud->set_subject(' ');
            $crud->unset_delete();
            //$crud->unset_jquery();
            $crud->unset_bootstrap();
            $crud->unset_export();
            $crud->unset_print();
            $crud->unset_read();
            $crud->unset_list();
            $crud->unset_back_to_list();
            $crud->unset_fields('v_started_date', 'v_end_date', 'v_active', 'user_id', 'v_event_counter');
            $crud->unset_edit_fields('v_started_date', 'v_end_date', 'v_active', 'user_id', 'v_event_counter', 'v_accept_agreement');
            $crud->display_as('v_name', __('Venue Name'))
                ->display_as('region_id', __('Region'))
                ->display_as('location_id', __('Location'))
                ->display_as('v_logo', __('Venue Logo'))
                ->display_as('v_address_1', __('Address 1'))
                ->display_as('v_address_2', __('Address 2'))
                ->display_as('v_city', __('City'))
                ->display_as('v_phone_number', __('Phone Number'))
                ->display_as('v_accept_agreement', '');

            // fields type
            $crud->set_field_upload('v_logo', 'assets/uploads/files');
            $crud->set_relation('region_id', 'regions', 'country');
            $crud->set_relation('location_id', 'locations', 'location');

            // dependent dropDown menu
            $this->load->library('gc_dependent_select');

            $fields = array(
                            // first field:
                            'region_id' => array( // first dropdown name //
                             'title' => 'country', //
                             'relate' => null // the first dropdown hasn't a relation
                            ),
                            // second field
                            'location_id' => array( // first dropdown name
                                'table_name' => 'locations',
                                'title' => 'location',
                                'id_field' => 'location_id',
                                'relate' => 'region_id',
                                'data-placeholder' => 'Select Location'
                            ));

            $config = array(
                'main_table' => 'regions',
                'main_table_primary' => 'region_id',
                "url" => base_url() .__CLASS__ . '/' . __FUNCTION__ . '/',
                'ajax_loader' => '',
                'segment_name' => '' // It's an optional parameter. by default "get_items"
            );
            $categories = new gc_dependent_select($crud, $fields, $config);

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

            // the second method:


            // callback function
            $crud->callback_add_field('v_accept_agreement', array($this, 'add_field_v_accept_agreement'));
            $crud->callback_after_insert(array($this, 'insert_start_date_after_insert'));

            // validation fields
            $crud->required_fields('v_name', 'v_accept_agreement');
            $crud->set_rules('v_accept_agreement', '', 'callback_required_field_v_accept_agreement_msg');

            // elements change text
            $crud->set_lang_string('form_save', __('Subscribe Now'));
            $crud->set_lang_string('insert_success_message',
                ' Your data has been successfully stored into the database.
                <br/>
                 Please wait while you are redirecting to the list page.
                 <script type="text/javascript">
                  window.location = "' . site_url() . '";
                 </script>'
            );

            $js = $categories->get_js();
            $output = $crud->render();
            $output->output .= $js;
            $this->load->vars($output);
            $this->layout->render_page('venue/index');

        }
    }

Php Power Arts
  • profile picture
  • Member

Posted 07 June 2016 - 07:13 AM

Hi Victor,

 

 

Thanks for this useful library. But, the Dependent Drop-down not working with latest GC 'assets'. I have tried this with old version 'assets' and new version 'assets'. I am using latest GC models (Grocery_crud_model.php: 1.5.4) and library (Grocery_CRUD.php: 1.5.4) in both (CI latest CodeIgniter 3.0.6).

 

Here is result:

 

GC 1.5.4 and latest 'assets' has working ajax and getting data properly but not populating drop-down. The select box still lock after getting ajax data.

Error_First.png

 

GC 1.5.4 and old 'assets' has working ajax and getting data properly and populating in drop-down, working fine

 

Working_Fine.png

 

 

Will you plz help me to fix this problem, I am stuck in a project. Your help would be much appreciated Victor :)

 

Download Code for test: https://drive.google.com/open?id=0B2Jr4ZrDD_hFdDlCRGhNMjZuY00

 

-Best

Neeraj Singh

i have the same issue like Neeraj


victor
  • profile picture
  • Member

Posted 10 June 2016 - 07:24 AM

Hello! The problems are because of the library has been done a few years ago. This weekend I will try to update the library to current GC version.


michael
  • profile picture
  • Member

Posted 10 June 2016 - 08:46 AM

Hello! The problems are because of the library has been done a few years ago. This weekend I will try to update the library to current GC version.

 

Dear Victor, nice to read that you take time for an update. I would be very happy if this great library would work with the current GC version. Thank you very much for your efforts.


Luca Chiaravalloti
  • profile picture
  • Member

Posted 22 June 2016 - 13:59 PM

I found the solution. It's very simple, it's only need to replace the string "liszt" with "chosen" into the library.

May be that the new version of Chosen library doesn't support anymore the liszt event.

I have attached the corrected Library.


victor
  • profile picture
  • Member

Posted 29 June 2016 - 16:55 PM

I found the solution. It's very simple, it's only need to replace the string "liszt" with "chosen" into the library.

May be that the new version of Chosen library doesn't support anymore the liszt event.

I have attached the corrected Library.

Yes. I've fixed that and made refactoring a bit. You can download the fresh version at the first page of the topic