Set dropdown input default value based on third parameter in Grocery CRUD

为君一笑 提交于 2019-12-22 09:24:09

问题


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 
}

回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/13819867/set-dropdown-input-default-value-based-on-third-parameter-in-grocery-crud

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!