False as default value for checkbox

Currently, when a checkbox field is created, the value is blank. This does not register in Dataview queries. Instead, you have to click the box twice so that it cycles: true > false. It would be easier if the value was false when the checkbox is created.

Use case or problem

It’s possible to use the checkbox field as a way of identifying three statuses, such as not to be invited, to be invited and invited. That would be: absence of checkbox, checkbox = false and checkbox = true. But just creating the checkbox doesn’t register as false. You have to click it twice.

Proposed solution

False is the default value for a checkbox.

Current workaround (optional)

Click twice.

5 Likes

I second this!
This is especially leading to problems when you for some reason edit your note in a way that you uncheck the previous checked checkboxes. Then you have some checkboxes that are false and some that are blank and everything is confusing.

1 Like

Or another workaround: Don’t test for “false”. Test for “not true”. Then it will capture both states.

6 Likes

Thank you. What is the query? where field = not true doesn’t work.

You’d have to check the plugin’s documentation. I said that as a concept, not syntax.

In the context of tasks, I believe the syntax is like this:

```dataview
TASK
WHERE !completed
```
2 Likes

Wouldn’t that just give you all the notes without the “completed” field? The challenge is to find a query that will select for:
completed:
not just completed: false.

Filtering by != true (“not true”) kind of means something like “everything but true”.

So, everything that’s explicitly true should be discarded whereas any other values, "" (blank) or false, should be kept by the filter.

That’s for the principle :blush:.

On the other hand, still as a concept, one can also explicitly filter by false OR "" (blank), which should return the same result as !=true .

1 Like

That’s very true! Good point.

The dataviewjs query would be:

```dataviewjs
dv.list(dv.pages().where(page => page.field === null || page.field === false))
```

Someone can chime in with the dataview query.

But I agree with your original request that false should be the default.

This gives all results for me, eg values where field === undefined === most pages.

I’ll admit I didn’t test dataview queries :sweat_smile:, I was speaking more generally… and I always forget about undefined :woman_facepalming:

On the other hand, while writing this, I’ve tested this query :

```dataview
TABLE check
WHERE contains(file.frontmatter, "check") AND check != true
```

check being a checkbox in Properties which seems to return the appropriate notes when check is blank or false (but finds nothing if check is true).

Don’t get me wrong though, I have nothing against having false as a default value for checkboxes :blush: .

That’s true (no pun intended). I hadn’t considered alternative checkbox values. I was mainly providing the !completed syntax as it seems to be what is used as opposed to true and false according to the Dataview documentation. So I guess it would only work for people who only have the box checked, unchecked, or undefined.

Thanks.

checkbox was implemented as tristate. default is empty.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.