Hi ! I 'm not good at English.I'm using grocery crud to build project, but i have a problem when i user field_type with dropdown field .When i get value from database using dropdown with value=1 , dropdown field have "selected" but when value="0" , downdown have not "selected". My code : $this->grocery_crud->field_type('status','dropdown',array('0'=>'Old','1'=>'New'));. I dont know why ! please help me
Bug ! Not "selected" dropdown field using field_type
- Single Page
Posted 31 October 2013 - 07:53 AM
Posted 20 January 2014 - 14:57 PM
I'm having the same problem.
I think it's like if 0 is reserved to "no value"
Posted 14 February 2014 - 15:55 PM
You're right, the get_dropdown_input function in the grocery_crud library does a 'is_empty' on the selected value. As 0 == empty in php, it thinks nothing is set.
I fixed this by editing around line 2337 in libraries/Grocery_CRUD.php:
$selected = !empty($value) && $value == $option_value ? "selected='selected'" : '';
change to:
$selected = !is_null($value) && $value == $option_value ? "selected='selected'" : '';
Which seemed to work.
Posted 07 November 2017 - 09:17 AM
Seems to be an old problem. It is still occurring today
Posted 28 February 2020 - 17:30 PM
2020, it still happens
Jay's solution works like a charm