I am currently working on a daily note template and have recently discovered the Modal Forms Plugin. It is pretty amazing for what you can do with it. Especially for how much easier it makes it for journaling.
However I am getting caught up currently, as I want to incorporate the Modal form into my daily note but I don’t want to run the Modal form when I create my daily note. My daily note hosts not just my journal but my tasks that are due today, anything overdue in terms of tasks, and some habit tracking as well. I would like to reference my other areas of my daily note early in the day and then at night when reflecting I want to be able to call the modal form and have the information input into my daily note.
For the most part I have this done, except the one hiccup is that I some fields in the Modal form are to be put in my front matter while other pieces are supposed to be under specific headers.
Things I have tried
My initial thought was to use the template like below but this only works if I use the form when creating my note
<% "---" %>
tags:
- dailynote
date: <% tp.date.now() %>
week: <% tp.date.now("[W]ww") %>
year: <% tp.date.now("YYYY") %>
<%*
const modalForm = app.plugins.plugins.modalforms.api;
const result = await modalForm.openForm("DailyNote");
tR += result.asFrontmatterString({ pick: [
"aka",
"enjoyment",
"mood"
] });
-%>
<% "---" %>
<% tp.web.daily_quote() %>
[[<% tp.date.now("YYYY-MM-DD",-1) %>|⬅️Yesterday]] - [[<% tp.date.now("YYYY-MM-DD",1) %>|Tomorrow➡️]]
[[<% tp.date.now("YYYY-[W]ww") %>|This week]]
# Journal
## What did I do today?
<% result.get("today") %>
## What made me feel *Nourished?*
<% result.get("nourished") %>
## What made me feel *Mastered?*
<% result.get("mastered") %>
## What made me feel *Depleted?*
<% result.get("depleted") %>
I have tried using the following quickadd code and then assigning it to a Meta Bind Button
When you’ve already got the note, you’ll need to use processFrontMatter() to update the frontmatter section. It’s a little bit of coding, but it’s usually quite reliable.
So after trying to integrate it is very similar to when I had a template and was using my Meta Bind button except now all the answers are in the frontmatter when I only want the first 3, and I want the others in the body of my text.
I used this modified version here
<%*
const modalForm = app.plugins.plugins.modalforms.api;
const run = async (frontmatter) => {
// Open your "DailyNote" form, preloading it with the current frontmatter values
const result = await modalForm.openForm('DailyNote', {
values: { ...frontmatter },
});
return result.getData(); // Return the updated form data
};
// Get the updated data from the form
const data = await run(tp.frontmatter);
// Update the frontmatter with the new data
app.fileManager.processFrontMatter(
tp.config.target_file,
frontmatter => {
Object.assign(frontmatter, data);
},
);
%>
Use this as your main template to create the Daily note
<%*
const dateAdded = tp.date.now('YYYY-MM-DD');
const week = tp.date.now("gggg-[W]ww");
const quarter = `Q${tp.date.now("Q")} - ${tp.date.now("YYYY")}`;
const month = tp.date.now("MMMM YYYY");
const year = tp.date.now("YYYY");
const metaData = `---
tags:
- "dailynote"
cssclasses:
aliases:
Date-Added: "[[${dateAdded}]]"
Week: "[[${week}]]"
Quarter: "[[${quarter}]]"
Month: "[[${month}]]"
Year: "[[${year}]]"
aka:
enjoyment:
mood:
---`;
tR += metaData;
const view = app.workspace.activeLeaf.getViewState()
view.state.mode = 'preview'
view.state.source = false
app.workspace.activeLeaf.setViewState(view)
%>
<% tp.web.daily_quote() %>
[[<% tp.date.now("YYYY-MM-DD",-1) %>|⬅️Yesterday]] - [[<% tp.date.now("YYYY-MM-DD",1) %>|Tomorrow➡️]]
[[<% tp.date.now("YYYY-[W]ww") %>|This week]]
# Journal
## What did I do today?
## What made me feel *Nourished?*
## What made me feel *Mastered?*
## What made me feel *Depleted?*
Assuming your creating the Daily Note first (without Modal Form)
Then create a Macro Choice in QuickAdd
1st Choice = Capture to Daily Note (active file)
Insert After “# Journal”
Capture Format below
<%*
const modalForm = app.plugins.plugins.modalforms.api;
const run = async (frontmatter) => {
// Prepare an object with only the properties you want to update
const selectedProperties = {
aka: frontmatter.aka,
enjoyment: frontmatter.enjoyment,
mood: frontmatter.mood
};
// Open the form with only these selected properties
const result = await modalForm.openForm('DailyNote', {
values: selectedProperties
});
return result.getData();
};
// Get the updated data from the form
const data = await run(tp.frontmatter);
// Update only the specified frontmatter properties
app.fileManager.processFrontMatter(
tp.config.target_file,
frontmatter => {
frontmatter.aka = data.aka;
frontmatter.enjoyment = data.enjoyment;
frontmatter.mood = data.mood;
}
);
%>
This updates
aka:
enjoyment:
mood:
for me in this case but I do get a console log error
“The file has been modified since the last read. QuickAdd could not merge the version without two conflicts and will not modify the file”
even though it updates the YAML Properties
RE: 1st Choice = Capture to Daily Note (active file) //if you change this to the actual name of the Daily Note and it’s not open then console log error doesn’t appear.