Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Is it possible to create select dynamically via API? #211

Closed
theotheo opened this issue Jan 17, 2024 · 6 comments
Closed

[Question] Is it possible to create select dynamically via API? #211

theotheo opened this issue Jan 17, 2024 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@theotheo
Copy link
Contributor

Hello, again!

As I understand it, the plugin has added the ability to create forms from the API. Please tell me if it is possible to set values for select.

I mean something like this

await modalForm.openForm('form', {
    values: {
        options: [
            { value: "pizza", label: "🍕 Pizza" },
            { value: "pasta", label: "🍝 Pasta" },
            { value: "burger", label: "🍔 Burger" },
        ]
    }
})
@theotheo theotheo added the enhancement New feature or request label Jan 17, 2024
@danielo515
Copy link
Owner

Interestingly, I was thinking about this in the very same morning you opened the issue.
However, in the same morning I thought: can't this be done with the dataview source? But I guess you have some different use-case in mind?
You can provide a full definition instead of a form name, but that is a overkill if you just want to override one single field of an existing form.

Please let me know what you want to achieve and I will try to add an easy way to do that. Something like this maybe?

await modalForm.openForm('form', {
    overrides: {
       fieldA: {
          options: [
            { value: "pizza", label: "🍕 Pizza" },
            { value: "pasta", label: "🍝 Pasta" },
            { value: "burger", label: "🍔 Burger" },
        ]
    }
  }
})

@theotheo
Copy link
Contributor Author

theotheo commented Jan 18, 2024

In my workflow, when completing a task, I enter some data. I'm filling out several select. Moreover, one of the options is a list of blocks on the page, which I receive dynamically. This list varies accordingly from page to page. If this can be done using dataview, then you still need to pass the page as a parameter.

I have now implemented via quickAddApi.suggestor. But QuickAdd doesn't allow you to combine multiple input elements into one form and is generally not that pretty. Having a successful experience using your plugin, I wanted to try making one form.

You can provide a full definition instead of a form name

I think this option will suit me too! But how to do it?

@danielo515
Copy link
Owner

In my workflow, when completing a task, I enter some data. I'm filling out several select. Moreover, one of the options is a list of blocks on the page, which I receive dynamically. This list varies accordingly from page to page. If this can be done using dataview, then you still need to pass the page as a parameter.

I don't know where that data is coming from yet, but I will help you anyway 😄

I have now implemented via quickAddApi.suggestor. But QuickAdd doesn't allow you to combine multiple input elements into one form and is generally not that pretty. Having a successful experience using your plugin, I wanted to try making one form.

Yeah, that was exactly my motivation to create this plugin, so you are in the right place

You can provide a full definition instead of a form name

I think this option will suit me too! But how to do it?

The open form method takes either a form name, or a form definition. If you build a form definition on the fly and then pass it as first argument, it will show you that form.
The easiest way will be to create a simple form, with a single input, copy it as json to your clipboard and then use that as a template.

await modalForm.openForm({
  "title": "Example form",
  "name": "example",
  "fields": [
    {
            name: "favorite_meal",
            label: "Favorite meal",
            input: {
                type: "select",
                source: "fixed",
                options: [
                    { value: "pizza", label: "🍕 Pizza" },
                    { value: "pasta", label: "🍝 Pasta" },
                    { value: "burger", label: "🍔 Burger" },
                ],
            },
      isRequired: false
    }
  ],
  "version": "1"
})

@danielo515 danielo515 changed the title Is it possible to create select dynamically via API? [Question] Is it possible to create select dynamically via API? Jan 20, 2024
@danielo515
Copy link
Owner

@theotheo can this be considered done?

@theotheo
Copy link
Contributor Author

theotheo commented Feb 4, 2024

Yes, this issue can be closed. Thank you very much for your advice. Your code helped me to handle my daily tasks more conveniently.

I would also like to mention that eventually, I went further and switched to using dataview-field. This is because the default select is not configurable.

"fields": [
    {
        name: "block",
        description: "blocks",
        input: {
            type: "dataview",
            query: JSON.stringify(contents)
        }
    },
    ...
    ```

@theotheo theotheo closed this as completed Feb 4, 2024
@danielo515
Copy link
Owner

danielo515 commented Feb 4, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants