danielo515 / obsidian-modal-form

Define forms for filling data that you will be able to open from anywhere you can run JS
https://danielorodriguez.com/obsidian-modal-form/
MIT License
187 stars 14 forks source link

Create a MultiSelect Form Field with Links to Obsidian Notes #230

Open ekbl1 opened 6 months ago

ekbl1 commented 6 months ago

Is your feature request related to a problem? Please describe.

Hi, I'd like to create a form field "Related Data" and be able to multiselect-add data that is links to notes, using a Dataview query like so: image

The dataview query I am using does work in the Form Builder:

dv.pages('"000_LifeOS/002_Data"').map(page=>page.file.link).sort()

I have WikiLinks enabled and the query above gives output like so in the Form Builder: image

But, the links do not show up in either the Form Preview or Rendered Form, when I try to fill out the form at this field.

In Form Preview and Rendered Form, "Related Data" is just an empty text box, even after I click into it. There is no drop down with links to select to add data to my multiselect field. image

Note: I have also used the following dataview query, which creates a list I can select from of what looks like the entire text string of a WikiLink:

dv.pagePaths('"000_LifeOS/002_Data"').map(path=>"\[\["+ path + "|" + dv.page(path).file.name + "\]\]")

This solution works to add links to a file's frontmatter property, but is messy during query writing and selection from the dropdown, imho. Please test it to see what I mean. The query could be more elegant with the page.file.link dataview property. And the modal form experience of selecting from the dropdown list doesn't show the links with the full file path on hover, as would be nice. Instead the modal form has you select the entire text of a wikilink from a list.

image

Describe the solution you'd like I'd like for the Modal Form to show a list of hyperlinked wikilinks to notes in the Form Preview and Rendered Form in a multiselect field, when using either query, above, but particularly when using the page.file.link property in a dataview query.

Additional context

Thank you for this plugin! It's wonderful. I am so excited about it.

mikerouxfr commented 6 months ago

Hello @ekbl1!

It seems an enhancement for the use case is on the way. I still wanted to share what I use just in case it's better for you, or others, in the meantime!

I use the fileLink function to build the link instead of creating the string myself:

dv.pagePaths('"000_LifeOS/002_Data"').map(path=>dv.fileLink(path))

It applies the filename as alias by default, but you could use your own with something like this:

dv.pagePaths('"000_LifeOS/002_Data"').map(path=>dv.fileLink(path,0,dv.page(path).aliases))