I set empty text and set 0 to be treated as empty. However, the empty text did not display for zero values. I discovered that this was because the data type was decimal and the precision was set to 2. "0.00" !== 0 is always TRUE.
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | 1789294-16.patch | 731 bytes | joelpittet |
| #15 | 1789294-15.patch | 728 bytes | joelpittet |
| #13 | 1789294-13.patch | 681 bytes | joelpittet |
| #3 | views-empty-decimal-values-1789294-3.patch | 1.02 KB | darren oh |
| #1 | views-empty-decimal-values-1789294-1.patch | 1018 bytes | darren oh |
Comments
Comment #1
darren ohComment #2
merlinofchaos commentedThat wont' work. The value 'foo' will show up as empty because 'foo' == 0. That's why we use !==
Instead youll have to use is_numeric I believe. If it's numeric you can test != and if it's not numeric you have to test !==
Comment #3
darren ohThanks. Updated patch attached.
Comment #4
darren ohComment #4.0
darren ohImproved formatting and corrected error.
Comment #5
emman31 commentedI have the same problem for Drupal 6. What is the best way to submit a patch? Should I create another issue?
Comment #6
Renee S commentedThis no longer applies, but the problem still exists.
Comment #7
guypaddock commentedSee #2450401: Multiple issues with is_value_empty().
Comment #12
crutch commentedDoes this patch work even though failed testing? Need this solution. Thanks
Comment #13
joelpittetHow about this? We just ensure we check
($value !== 0 && $value !== '0')Comment #14
joelpittetWhoops that doesn't cover the float from the original issue just the integers.
Comment #15
joelpittetOk this should work better.
$is_zero = is_numeric($value) && !((float) $value);Covers as 0:
0, 0.00, 0.000, '0', '0.00', '0.000'Will ensure these don't count as 0:
'', '0.000001', 0.000001And in the case where 'empty_zero' == TRUE, it will count '0.000' as a 0 value, and let it pass to set it to '' as I'd expect
This should really get some tests I suspect.
Comment #16
joelpittetWhile testing I still got it a bit off, it was assuming NULL was allowed not be empty the way the conditional was written.
Comment #18
chris matthews commentedThe 2 year old patch in #16 to views_handler_field_numeric.inc applied cleanly to the latest views 7.x-3.x-dev, but still needs review.
Comment #19
damienmckennaThis is a near complete duplicate of #1782304: Can't use "rewrite if empty" on fields using views_handler_field_numeric, only that one has test coverage too.
Could everyone here please try out the patch over there to confirm it works for you? Thanks.