Using metaedit, buttons, templater, nldates and dataview together

Thanks to @shabegom (author) and my unusual use case, this dataview script was born.
As the title says, you need the 5 plugins installed and enabled for this to work.

```dataviewjs
const {createButton} = app.plugins.plugins["buttons"]
const {update} = app.plugins.plugins['metaedit'].api

const defer = async (file, key) => {
    const value = await app.plugins.plugins['templater-obsidian'].templater.functions_generator.internal_functions.modules_array[4].static_functions.get('prompt')("What Date")
    const date = app.plugins.plugins['nldates-obsidian'].parseDate(value).moment.format("YYYY-MM-DD")
    await update(key, date, file)
}

dv.table(
["Name", "Date", "Bouton"],
dv.pages("#task").map(t => [t.file.link, t['date'],
createButton({app, el: this.container, args: {name: "Change date"}, clickOverride: {click: defer, params: [t.file.path, 'date']}})])
)
```

With this, you can update date metadata in notes using natural language (without leaving the current note) by clicking on buttons in a dataview table

Screen Recording 2022-04-15 at 10.22.36 PM

What we’ve got here is a mashup of 5 different plugins

  1. Dataview renders the table
  2. Buttons puts a button in the table
  3. When a button is clicked, Templater renders a prompt for a date
  4. Natural Language dates takes the prompt input and formats as an actual date
  5. Meta edit updates the YAML of the specified note with the date

Special thanks to @AB1908 for reminding me to post this here, so that it doesn’t get lost in discord.

28 Likes

Thanks a lot for sharing this!

How would one adapt this to creating a button to change a yaml field or inline field in the same file?

Happy to help.

How would one adapt this to creating a button to change a yaml field or inline field in the same file?

What do you mean ? it’s already changing the metadata in the files.

I tried adapting but I was unsuccessful :stuck_out_tongue:

What I mean is that I want to be able to edit a metadata field of the current note in preview mode. So basically, access the current note’s metadata field, click a button, have prompt, enter text, and update it.

I was able to access a text field using dv.current()[“name text field”] and display it, but then I got stuck adapting the “createbutton” and “defer” function so that it would update correctly

Same thing, just pass dv.current().file.path instead of the dynamic page path.

Thanks for sharing! Do you know how to make the button trigger the autoprop instead of the templater?

I have the following code snippet, but the button does nothing (and the value returned is just null)

const {update, autoprop} = this.app.plugins.plugins["metaedit"].api
const {createButton} = app.plugins.plugins["buttons"]

const defer = async (file, key) => {
    const value = await autoprop(key)
    await update(key, value, file)
}

const updateButton = (t) => createButton({app, el: this.container, args: {name: "Done"}, clickOverride: {click: defer, params: [t.file.path, 'status']}})

dv.table(["File", "Date", "Role", "Place", "Status", "Source", ""], dv.pages("#tag_list")
	.sort(t => t["status"], "asc")
	.where(t => t.status != "Rejected")
	.map(t => [t.file.link, t["date"], t["role"], t.place, t.status, t.source, updateButton(t)])
)

This used to work for me, but now the prompt doesn’t show and I’m not sure what changed.

Does this still work for people?

Plugin versions:

  • Obsidian v1.5.3
  • Buttons v0.4.19
  • Dataview v0.5.64
  • MetaEdit v1.8.2
  • Natural Language Dates v0.6.2
  • Templater v2.1.2

I do not know. I don’t even have this script, to be honest.

But I have two ideas:

  • Since then, core Properties came out.
  • Buttons should(?) work but is no longer maintained, I hear. The Meta Bind plugin incorporated Buttons (no idea if the syntax used is the same or not).

In the Properties UI you can click on any key and edit it from there.

To be honest, I stopped using most of the plugins in this showcase :

  • dataviewjs because of the flickering, I’m waiting for datacore.
  • button because was always a bit buggy, metabind is more active and provide nearly the same features.
  • As for the metaedit, it was always creating weird errors in the console, so I switched to metadata menu, and it provides nice additions to the new properties feature