⚠ 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

issue with field_type dropdown



aramishvili
  • profile picture
  • Member

Posted 26 July 2017 - 15:21 PM

Hello, I'm new here and have stumbled on a problem when using field_type dropdown with an array that goes something like this

 

array('0'=>'zero', '1'=>'one'... etc.

 

The problem is that when the value is 0 the dropdown does not select it when editing.

 

How can I work around this issue? 

 

Changing the table in database to start from 1 is not an option.

 

dRzOKwB.png


aramishvili
  • profile picture
  • Member

Posted 26 July 2017 - 16:11 PM

Solved this issue by modifying the function "get_dropdown_input" in "application/libraries/Grocery_CRUD.php".

 

On line 2405 I changed this:

$selected = !empty($value) && $value == $option_value ? "selected='selected'" : '';

to this:

$selected = !is_null($value) && $value == $option_value ? "selected='selected'" : '';

The issue was caused by the fact that empty() returns true on 0.


goshikamahi
  • profile picture
  • Member

Posted 24 June 2019 - 06:39 AM

Hi @aramishvili,

 

Thanks for help. you saved my time


Yazid
  • profile picture
  • Member

Posted 07 October 2019 - 06:51 AM

I use the latest GC community, but still get this issue, but your solution @aramishvili saved my day, three thousand thanks !