"Hide if empty" ignored for fields

Created on 29 February 2024, 10 months ago

Problem/Motivation

An empty row is output, even if "Hide if empty" is enabled for the field.

Steps to reproduce

  1. Add a field in a view
  2. Enable "Hide if empty"
  3. See empty rows in the output

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Active

Version

11.0 🔥

Component
Views 

Last updated about 3 hours ago

Created by

🇩🇰Denmark ressa Copenhagen

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @ressa
  • 🇩🇰Denmark ressa Copenhagen
  • 🇩🇰Denmark ressa Copenhagen
  • Status changed to Postponed: needs info 10 months ago
  • 🇳🇱Netherlands Lendude Amsterdam

    Tried to reproduce, and this seems to be working as designed. The option that is enabled in the screenshot and the steps is about hiding an empty field, which it is (the row is empty in the screenshot). What is not hidden is the empty row. There is nothing saying that this setting should bubble up and hide the whole row (if all fields are empty and all fields have this option enabled?). Right?

    If you want to hide rows that don't have content in a certain field, that would need a filter.

    Am I reading this correctly or is there something here that I'm overlooking?

  • Status changed to Active 10 months ago
  • 🇩🇰Denmark ressa Copenhagen

    Thanks for looking at this. Perhaps it's the wording which is the challenge here then?

    With the current wording, my assumption is that if "Hide if empty" is enabled the field including the empty row would be skipped, so that <div class="views-row"></div> would not be output. But it sounds like that's not the case.

    I understand a filter like Content: Image:target_id (not empty) should be used instead, and this works well.

    But what is the meaning of "Hide if empty" then? Like, what's the use case?

  • 🇳🇱Netherlands Lendude Amsterdam

    A use case I can see: If you have multiple fields in a row and only want to show the wrapper for that field if it has a value?

    Since it would be up to the plugin rendering the row to do something with the information from the fields, it would be very hard to bubble this setting up to the row consistently.
    That would need to be implemented in all Style and/or Row plugins individually, sort of like what the Table Style does with the empty_column setting.

    So to me this is 'Works as designed'. The setting in the field should control that which it has control over: only that field.

    But yeah, better wording might help, although the description is already pretty extensive: "Enable to hide this field if it is empty. Note that the field label or rewritten output may still be displayed. To hide labels, check the style or row style settings for empty fields. To hide rewritten content, check the "Hide rewriting if empty" checkbox."

  • 🇩🇰Denmark ressa Copenhagen

    Thanks for the explanation, though I still don't understand what "Hide if empty" actually means in this context then :)

    I even tried to disable "Add views row classes", and an empty div is output: <div></div>.

    I think I may understand it, if you could describe the steps for me to actually hide it ... is that possible? Because I am trying hard to do what the text says ("Hide if empty") but keep failing ...

    When we reach that point where something can be hidden, we can look at how to rewrite the help text, to make it immediately understandable?

  • 🇫🇮Finland Nchase

    I kind of having the same problem. To extend this issue: When I attach a class to that field for example in order to show a background-image - let's say a maps icon, then that icon shows up no matter what - as the empty view is empty but the views-field class with the additional class as span is still in the code. Hence the icon is visible, taking up space, and causing frontend problems.

    The text is misleading. In the settings it says: "Do not display fields, labels or markup for fields that are empty." - but the actually markup is showing up - Like for example:

    <div class="views-field views-field-field-address-country-code"><span class="field-content icon-place"></span></div>

    It is not user-friendly this way and kind of counter-intuitive for frontend developers.
    I know have to find a way to really hide the entire views-field div.

Production build 0.71.5 2024