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



kenshicu
  • profile picture
  • Member

Posted 15 March 2013 - 22:20 PM

I will try that, thank you very much :)
So now I have to do in the library, I can not do it on the same controller (more dynamic and customizable)


victor
  • profile picture
  • Member

Posted 15 March 2013 - 22:25 PM

try to do it


kenshicu
  • profile picture
  • Member

Posted 15 March 2013 - 22:50 PM

I added this: ('where' => 'country_id = '13' ") in the first field (country)
I put the country_id = 13 directly to test, and it did not work. :wacko:


victor
  • profile picture
  • Member

Posted 15 March 2013 - 22:53 PM

draw a scheme of your tables


victor
  • profile picture
  • Member

Posted 15 March 2013 - 22:54 PM

and explain in more detail how it must works


kenshicu
  • profile picture
  • Member

Posted 15 March 2013 - 23:10 PM

My schedule is very large, complex and is in Spanish, but basically is the same as your example. But what I want to achieve is that when you add or edit a record in the table (dd_goods), the selectbox (goods_country) only shows the country of the user who is using the system. Currently showing all countries: (
I think the solution is around the code you gave me


Kanakdeep
  • profile picture
  • Member

Posted 16 March 2013 - 07:40 AM

Hi Victor,

 

Please see my message before...any idea?


victor
  • profile picture
  • Member

Posted 16 March 2013 - 11:54 AM

Give me a database dump of your tables.

kenshicu
  • profile picture
  • Member

Posted 16 March 2013 - 21:43 PM

Victor, in the controller (dd_goods) i did a callback_field for the parent selectbox:
$crud->callback_field ( 'country_id', array ( $this, '_callback_1' ) );

and it works, but can pass parameters to a this callback? to do dynamic

    function _callback_1($value = '', $primary_key = null)
    {
        $this->db->select ( '*' );
        $this->db->from ( 'dd_country' );
        $this->db->where ( 'country_id', '13' ); // 13 is a id for test
        $result = $this->db->get ();
        $data = $result->row ();    
    $html = '<select name="country_id" class="chosen-select" data-placeholder="Select Country" style="width: 200px;">';
    $html.= '<option value=""></option>';
    $html.= '<option value="'.$data->country_id.'" >'.$data->country_title.'</option>';
    $html.= '</select>';
    return $html;
    }    
    
Note: I'm trying to filter the parent dropdown


victor
  • profile picture
  • Member

Posted 16 March 2013 - 22:39 PM

If you want to change the parent dropdown you can use callback function as you like. The library doesn't touches to the parent dropdown.

For example you can use callback_add_field and callback_edit_field for the first doropdown of this system


kenshicu
  • profile picture
  • Member

Posted 16 March 2013 - 23:06 PM

ok, thanks

I think I will use the callback_field for this.
any idea how to pass data
as parameters to the callback_field function? , is that I use this function a lot, thanks again.


josemaGC
  • profile picture
  • Member

Posted 17 March 2013 - 02:56 AM

Victor,
First, sorry for my bad English (this is google translation).
In your example, in the first post of this thread, your tables 'main' have fields containing the tables id's city, state and country.
my table 'main' (as dd_goods, for example) only contains goods_city field, because a city is in a single state, and a state is in a single country.
Can I use your library ID dropdown when fields do not exist in table 'main'?. When adding a record in the table, create a 'select' with all countries, after selecting a country, create a 'select' with only the states of selected country, and selecting a state, create a 'select' with only the cities in that state. When recording the record, just save the id-city.
 
Thank you very much.

victor
  • profile picture
  • Member

Posted 17 March 2013 - 09:08 AM

sorry, josemaGC, but my library based on the fields from main table.

victor
  • profile picture
  • Member

Posted 17 March 2013 - 09:08 AM

sorry, josemaGC, but action of my library based on the fields from main table.

Kanakdeep
  • profile picture
  • Member

Posted 28 March 2013 - 04:43 AM

Any idea Victor? I sent the database dump by private message. MY problem is stated in message #176.


victor
  • profile picture
  • Member

Posted 28 March 2013 - 21:06 PM

Hi, guys! I'm sorry. I have no time at all to help you in this week. I have too much work. Very much...

I have a heavy time now  :wacko:

I am very tired every day.


elfuego1
  • profile picture
  • Member

Posted 31 March 2013 - 00:59 AM

Hi,

 

I tried to use your library

I used the code from your example data located on the first page and got an error:

 

Error Number: 1064

You have an error in your SQL syntax:

 

SELECT dd_country., dd_country.country_title as se3dbd3a3 FROM (`dd_country`) ORDER BY `se3dbd3a3`
 

I also tried to use callback_add_field for the first dropdown field. It helps and the add page is loading but there is no first dropdown in the form.

 

Is there a bug in the example or am I doing something wrong?


victor
  • profile picture
  • Member

Posted 31 March 2013 - 20:59 PM

Can you show your code where you get this error? 


elfuego1
  • profile picture
  • Member

Posted 04 April 2013 - 21:21 PM

Thanks.

Just managed to solve the problem.


victor
  • profile picture
  • Member

Posted 09 April 2013 - 22:17 PM

I have a few days to answer on your querstions.