From f8a2b29bd2950c92a2009eb2720000a7f8fed0fe Mon Sep 17 00:00:00 2001 From: Danielo Rodriguez Date: Thu, 26 Oct 2023 17:01:20 +0200 Subject: [PATCH] docs: FormResult methods --- README.md | 6 ++++- src/docs/magaing-results.md | 46 +++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/docs/magaing-results.md diff --git a/README.md b/README.md index 27900126..06b8974f 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,8 @@ Here you have an example screenshot of how it should look like: ### FormResult Methods -The `FormResult` object returned by the `openForm` method has several methods that can be used to process the form data. Here is a brief description of each method: +When you open a form, you get back a `FormResult` object. This object contains the data of the form and some methods to help you process it. +This `FormResult` object returned by the `openForm` method has several methods that can be used to process the form data. Here is a brief description of each method: #### asFrontmatterString() @@ -136,6 +137,9 @@ tR += result.asString('{{Name}} is {{age}} years old and his/her favorite food i -%> ``` +#### Advanced usage + +For more advanced usage of the `FormResult` methods please refer to the specific documentation of FormResult [here](docs/managing-results.md) ### Define a form diff --git a/src/docs/magaing-results.md b/src/docs/magaing-results.md new file mode 100644 index 00000000..6b3fe846 --- /dev/null +++ b/src/docs/magaing-results.md @@ -0,0 +1,46 @@ +# Managing Results + +The `FormResult` class provides methods for managing form results. + +## `asFrontmatterString(options?: unknown): string` + +Transforms the current data into a frontmatter string, which is expected to be enclosed in `---` when used in a markdown file. This method does not add the enclosing `---` to the string, so you can put it anywhere inside the frontmatter. + +### Parameters + +- `options` (optional): An options object describing what options to pick or omit. + + - `pick` (optional): An array of key names to pick from the data. + - `omit` (optional): An array of key names to omit from the data. + +### Returns + +- `string`: The data formatted as a frontmatter string. + +### Example + +```typescript +const result = await form.openForm('my-form') +tR += result.asFrontmatterString({ pick: ['title'] }); +``` + +## `asDataviewProperties(options?: unknown): string` + +Returns the current data as a block of dataview properties. + +### Parameters + +- `options` (optional): An options object describing what options to pick or omit. + + - `pick` (optional): An array of key names to pick from the data. + - `omit` (optional): An array of key names to omit from the data. + +### Returns + +- `string`: The data formatted as a block of dataview properties. + +### Example + +```typescript +const result = await form.openForm('my-form') +tR += result.asDataviewProperties({ pick: ['title'] });`