3

Code sample below,

function product($parameter){

   $crud = new grocery_CRUD();
   ...
   $crud->callback_add_field('dropdown_field_name',array($this,'_add_field_callback'));
   ...
   $output = $crud->render();
}

Can I do something like this ?

function _add_field_callback($parameter){
   //load db model
   //call the result and return as dropdown input field with selected selection when value = $parameter 
}
Jonas Czech
  • 12,018
  • 6
  • 44
  • 65
Bravo Net
  • 805
  • 5
  • 17
  • 30

2 Answers2

4

Actually this is easy to do it by using the controller. For example you can simply do:

function product($parameter){

    $this->my_test_parameter = $parameter;

   $crud = new grocery_CRUD();
   ...
   $crud->callback_add_field('dropdown_field_name',array($this,'_add_field_callback'));
   ...
   $output = $crud->render();
}

And the callback:

function _add_field_callback($parameter){
   //load db model
   //call the result and return as dropdown input field with selected selection when value = $parameter 

   $value = !empty($this->my_test_parameter) ? $this->my_test_parameter : '';
   ...
   //here you can also use the form_dropdown of codeigniter (http://ellislab.com/codeigniter/user-guide/helpers/form_helper.html)
}   

I know that you are desperately looking forward for the default value for grocery CRUD so I added an issue to the github https://github.com/scoumbourdis/grocery-crud/issues/138 . This is will be a reminder that this thing has to be fixed.

John Skoumbourdis
  • 3,041
  • 28
  • 34
  • thanks john! u r such a responsible developer! you gain my respect! the only thing i am not sure is why we need to insert this "$this->my_test_parameter = $parameter;" and it can callback in another function. – Bravo Net Dec 26 '12 at 02:25
  • Well... Thanks :) . The reason that I am using the $this->my_test_parameter is that there is not another way to pass a custom variable to the callback. Grocery CRUD doesn't support custom parameters yet so for now this is the best way to use it. If the question is that we can call the "$this" into the callback the answer is YES as we are still at the same Controller – John Skoumbourdis Dec 26 '12 at 03:16
0

I had implemented Grocery Crud in one of my web application.

Check this link on " How to create dependent dropdowns"

http://demo.edynamics.co.za/grocery_crud/index.php/examples/customers_management/add

Vaibhav
  • 289
  • 1
  • 3
  • 11
  • i saw this tutorial previously.. it is not what i want. but it's certainly a good guide for me in future use. thanks! – Bravo Net Dec 26 '12 at 02:17