Hi,

i use the proximity search with views and it works fine.
showing the distance field and hiding it, if it is empty also works fine.

when i choose round and precission 2, then the "empty" fields with 0.00 will not be hidden.

does anyone has an idea how to fix this?

Comments

Golem07’s picture

Issue summary: View changes

I'd be very interested in a solution to this as well.

dmegatool’s picture

Yeah this is a bug. I'm not a coder so I don't have a fix or patch for it.

But here's how I managed to hide my field if it's empty.

  • Install Views PHP
  • Uncheck the round option on the proximity field (we'll round it with the php field)
  • In the Output code of a Global PHP field, use <?php print round($row->field_geofield_distance, 1); ?> Adjust the variable so it use your proximity field. The 1 is the precision so it will output ex: 3.1
  • Check Count the number 0 as empty
  • Check Hide if empty
  • Check Hide rewriting if empty
  • Check Rewrite the output of this field
    • Distance : [php] km (Adjust the token to use the current Global PHP field we're working on)

So that's about it, it should work. Note that this leaved me with an empty line caused by <br></br> in the DOM. I couldn't remove it so I hacked around with css like so :

  • In the Global PHP field, under No results behavior / No results text, I added a div <div class="emptyDistance"></div>
  • I then used .emptyDistance {display: block; margin-bottom: -1rem;}
  • in my css and it was all good. Of course adjust the margin to your liking if your doing this.

So all in all, we're just rounding using PHP instead of the default proximity field. It still should be fixed as this is a bug and users are expecting it to work.

dmegatool’s picture

Seems like it's a Views issue ?

Discussed here. There's even a patch (I didn't test it).