imed
April 15, 2022, 9:32pm
1
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
What we’ve got here is a mashup of 5 different plugins
Dataview renders the table
Buttons puts a button in the table
When a button is clicked, Templater renders a prompt for a date
Natural Language dates takes the prompt input and formats as an actual date
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 .
27 Likes
y.h
October 16, 2022, 5:27pm
2
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?
imed
October 16, 2022, 8:31pm
3
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.
y.h
October 17, 2022, 8:15am
4
I tried adapting but I was unsuccessful
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)])
)