Jump to content


How can i add one fake field as Dropdownlist?

fake field dropdown

  • Please log in to reply
2 replies to this topic

#1 sureshkumar039

sureshkumar039

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 17 July 2013 - 07:56 AM

I have a problem in grocery crud. In my Form display category dropdown list and Subcategory dropdown list. Those two are dipendent dropdown lists. But in my database have only one field thet is "subcategory_id". so my problem is How can i take two dropdowns with one field in database.

or How can i take one fake field(custom field) as dropdownlist.

Please give any solution to this..



#2 sureshkumar039

sureshkumar039

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 17 July 2013 - 08:10 AM

My data bse field are

table name: t_category

category_id

category_name

 

table name: t_category

sub_category_id

sub_category_name

 

 

table name: t_news

 

news_id

news_name

sub_category_id

news_title

discription

 

In my news form i need category and sub category dropdowns. But in my news table i have only one field that is 'sub_category_id'. So how can i take two fields in form with one one field(in database).

 

Iam adding one fake field(custom field) for category drop down that is:

 

I wrote in my controller

 

$crud->fields('category_id','sub_category_id','news_title','discription');

 

$crud->callback_add_field('category_id',array($this,'add_field_callback_1'));

 

 

 

function add_field_callback_1()
            {
             $this->load->library('grocery_CRUD');    
            $crud = new grocery_CRUD();
            
     $empty_select = '<select id="field-category_id" name="category_id" class="chosen-select chzn-done" data-placeholder="Select Category" style="width: 300px;display: none;"><option value=""></option>';
    
            $empty_select_closed = '</select>';
            $empty_select_closed1='<div style="width: 300px;" class="chzn-container chzn-container-single" id="field_category_id_chzn">
                    <a href="javascript:void(0)" class="chzn-single chzn-default" tabindex="-1">
                    <span>Select Category</span><div><b></b></div></a>
                    
                    <div class="chzn-drop" style="left: -9000px; width: 510px; top: 30px;"><div class="chzn-search">
                    <input style="width: 490px;" autocomplete="off" type="text"></div>
<ul class="chzn-results">';

             $this->db->select('*')
                         ->from('t_category')
                         ->where('module_id', 24);
                $db = $this->db->get();
                $i=1;
                foreach($db->result() as $row):
                
                     $empty_select .= '<option value="'.$row->category_id.'" >'.$row->category_name.'</option>';
                     $empty_select_closed1.='<li id="field_category_id_chzn_o_'.$i.'" class="active-result" style="">'.$row->category_name.'</li>';
                     $i++;
                endforeach;
                
                $empty_select_closed1.='</ul></div></div>';
                
                
    $html = '<link type="text/css" rel="stylesheet" href="'.base_url().'/assets/grocery_crud/css/jquery_plugins/chosen/chosen.css" />';
    $html .= '<script src="'.base_url().'/assets/grocery_crud/js/jquery_plugins/jquery.chosen.min.js"></script>';
    $html .= '<script src="'.base_url().'/assets/grocery_crud/js/jquery_plugins/config/jquery.chosen.config.js"></script>';
                
                return $empty_select.$empty_select_closed.$empty_select_closed1;
            }

 

 

Drop down list is coming. But is not working..? Please give any solution?

 



#3 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

Posted 17 July 2013 - 11:47 AM

Well the question here is, how are you relating your category with sub-categories.. there should be a set criteria na... like this sub-category belongs to this category.. then is the meaning of setting a dependent drop down.

 

I will recommend you first have a category_id in the sub_categories table and then you can use the following

http://www.grocerycr...opdown-library/

 

Here it will show as how can you have a dependent drop down in grocery crud







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users