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.

22 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.