Filter to Show Tiddlers with a Specific Empty Field

  • There are tiddlers have field myfield and tagged with qst
    • some of them have field with no value (empty)
    • some have value in the field myfield including text, only whitespace (tab, space)
  • There are tiddlers have NOT field myfield and tagged with qst

I am looking for a TW correct script to filter all tiddlers tagged with qst, have the field myfield BUT with no value (empty) or whitespaces (again empty)

Hmmm it seems to me like it should be:

[tag[qst]has:field[myfield]!regexp[\S]]

but that doesn’t seem to be working for me… maybe that gets you closer though.

  • The has:field thing is part of it - see: https://tiddlywiki.com/#has%20Operator
  • The \S should be any non-space character, so excluding it should leave you with only nulls/spaces, but in my quick testing it doesn’t seem to do that.

[tag[qst]has:field[myfield]] :filter[{!!myfield}trim[]is[blank]then[yes]]

1 Like

The has operator return a list of titles of tiddlers, then you aren’t using regexp operator in the field else it is used in the title.

The following filter may be what you need

…has:field[fieldname]!has[fieldname]

First it tests if the field exists regardless of content, then tests if it does NOT exist (but we know it does) or has NO value.

If the white space causes problems you could ask is[blank] or institutes regex only then.

Perhaps a batch to clear out inconsistent whitespace makes more sense.

@saqimtiaz solution works fine!
@TW_Tones only returned empty field but ignores those have white-spaces!

1 Like

A reverse question:

Can I return those tiddlers tagged with qst and has NON-empty field myfield?

If both no value and whitespace are interpreted as empty then using Saq solution in TW 5.2.0

<$list filter="[tag[qst]has:filed[myfield]] :filter[{!!myfield}trim[]!is[blank]]">

<$link/> - <$transclude/>
</$list>

If a field ONLY with no value considered empty but whitespaces is considered nonempty then in older TW you can have:

<$list filter="[tag[qst]!field:myfield[]]">

<$link/> - <$transclude/>
</$list>

More info can be found in: https://tiddlywiki.com/#field%20Operator and TW-Scripts

I do not have the test data but get[fieldname] is like a has:field and returns the tiddler value.

[tag[qst]get[myfield]is[blank]get[title]]

I understand this is solved but think there is a simpler way than the selected solution. If is[blank] is not robust enough you could add trim.

As I said before if fields contain unwanted other white space I would simple clean them up so the has[fieldname] works.

Another nut to crack in the field of empty-fields
How do I filter tiddler who do not have a field section-type … not even an empty one.
I tried this:
[all[current]!has:field[section-type]] :filter[{!!section-type}trim[]is[blank]]

But this also shows Tiddlers with existing empty fields.

What is the second filter all about?

  • You are trying to handle the field you want to “not exist” in the first filter

That is why I am asking this question. With the first part I also get the empty section-type fields, which I wanted to exclude.

I am still trying to determine what you want (perhaps my problem). The original question in thread related to a special case where the field may contain whitespace. Is that what you are asking for?

So let us return you your question

If exclude the white space issue

That is if in a tiddler tagged $:/tags/ViewTemplate

<$list filter="[all[current]!has:field[section-type]] :else[{!!section-type}is[blank]]">
   No section-type
</$list>
  • The first part of the filter is true if there is no section-type even empty, we say “No section-type”.
  • If the first is not true ELSE then “section-type” contains something
    • but we test if its blank and if so we say , we also say “No section-type”.
  • If there is a chance of whitespace other than blank/spaces we can add trim as before.
    [all[current]!has:field[section-type]] :else[{!!section-type}trim[]is[blank]]

Is this what you want @JanJo ?

Hi Tony, thanks but not yet -
the filter still shows tiddlers with an empty section-type field. The viewtemplate I need the filter for should be invisible there.

If the field is empty this should be sufficient:
[all[current]!has:field[section-type]]

If it has whitespace for content:

[all[current]!has:field[section-type]] :filter[get[section-type]trim[]!is[blank]]

1 Like

Hi @saqimtiaz, thank you
[all[current]!has:field[se-type]] does the job .