From d7bf3cdc3321c5cf32a29e0efd930a8c78963363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Rodr=C3=ADguez=20Rivero?= Date: Thu, 16 Nov 2023 08:45:41 +0100 Subject: [PATCH] Update advanced-examples.md --- docs/advanced-examples.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/advanced-examples.md b/docs/advanced-examples.md index 8ec9bc5e..e298a26f 100644 --- a/docs/advanced-examples.md +++ b/docs/advanced-examples.md @@ -5,3 +5,20 @@ In this section of the docs you will find some advanced usage examples of modal- ## Nesting form calls ## Modifying frontmatter with a form + +If you want to modify the content of a notes frontmatter with one of your existing forms, put the following +snippet in a templater template, substituting the name of your form: + +```js +<%* +const modalForm = app.plugins.plugins.modalforms.api; +app.fileManager.processFrontMatter(tp.config.target_file, + async (frontmatter) => { + const result = await modalForm.openForm('example-form', { values: {...frontmatter}}); + Object.assign(frontmatter, result.getData()); + })}, 200) +%> +``` + +The values the form understand and that are pressent in the frontmatter, will be populated with the values on the frontmatter. +Then, when you submit the form, the new values will overwrite the old ones, leaving the rest untouched.