Append Options to Dataviewjs Query in Metadata Menu

What I’m trying to do

I’m wondering if it is possible to append options to a dataviewjs query in the Metadata Menu plugin for a field. For example, the query for one multiple links field is this:

dv.pages().where(p => p.file.folder.includes("Groups"))

And it gives me all files with Groups somewhere in their folder name as an option, but is it possible to add one last choice?

For example, say my file does not correspond to any group at all. It would be nice to have a None option. Not sure if that’s possible with a multiple-links field, but even if this was a multi-select field instead, would it be possible to append extra options to a query?

Things I have tried

I’ve tried some things like, dv.pages().where(p => p.file.folder.includes("Groups")) || "None". Didn’t expect that one to work anyway. I also tried dv.pages().where(p => p.file.folder.includes("Groups")).push("None"). I don’t know how to create a string and make dataview register it as a file name.

If anyone knows how to do this, or even if it can be done, it’d greatly appreaciate it. Thanks! :star:

And of course, I’m aware that it would take less than a second to type “None”, but I’m really just curious to know if this is possible.

let data = dv.pages().where(p => p.file.folder.includes("Groups"))

I’m wondering how will you use it? Do you have full access to javascript, or is it just a query in a field to be eval’ed?

Would it be an option to create a real page, matching your query and use that as a none-page? In other words an empty page, with just enough metadata to trigger your query, and some marker to denote it’s your none-page?

How do you plan to detect, in either case, that this is your none-option?

I could create a “None” page in this example, but I’d rather have it appear as text, “None”. I usually use the metadata menu modal to add metadata, and there is no “None” option for links. So I was wondering if I could conveniently append a “None” to the query.

The plugin does not seem to have all the capabilities of javascript, because it will just take the dv.pages() query. Words like let and var don’t do anything because it is only looking for the dv.pages() function.

I also tried dv.pages().where(p => p.file.folder.includes("Groups")).push(p => = "None"), but that didn’t work.

One of the points I’m getting at is that if you add it to the query result, how will it not be a page link? And if that’s the case, then why not just make that page as dummy page, and rather deal with it specific in the other code related to your metadata menu modal?

I suspected that, so that kind of eliminates the option of adding a pure text entry anyways. So I do believe adding a dummy page into your query is one of the better options (as long as metadata doesn’t offer a none option itself). And given a “proper”/obivous page name like “None” or “-- None --”, you should be able to spot it rather easily in your frontmatter (or wherever you store the value.

In a pure javascript environment other options could exist, like adding some other page variant containing the bare minimums like the display text, and whatever metadata pulls out as a value.

Yeah, I see what you mean. I guess my real question was, is it possible to append an extra option to the existing options after the query? But then that’s more of a metadata menu question than a dataview question, I suppose.

So, not actually adding anything to the query. The query will always return a page. I was wondering if I could use the options generated by the query, and add an extra option to that. Like, push another option, not another page.

Again, I can always just go to the field and type “None”, and I guess I should just accept that as my solution. But if it’s possible…I guess in reality, I just really want to know if it is possible.

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