mProjectsCode / obsidian-meta-bind-plugin

A plugin for Obsidian to make your notes interactive with inline input fields, metadata displays, and buttons.
https://www.moritzjung.dev/obsidian-meta-bind-plugin-docs/
GNU General Public License v3.0
490 stars 40 forks source link

Conditionally show/hide buttons #440

Open sanyam opened 1 day ago

sanyam commented 1 day ago

Please fill out these Check-boxes

Is your Feature Request related to a Problem or Annoyance?

No response

Describe the Feature you'd like

Is it possible to somehow show/hide buttons depending on the current value one of the properties? I am trying to make something like the workflow in Jira. So, depending on the status of the current tasks, i want the some buttons with the possible next statuses are shown. Something like:

property status = Backlog -> the button "InProgress" is shown property status = InProgress -> the buttons "Backlog" and "Done" are shown and etc.

somekind of conditional show/hide for the button

Alternatives

No response

Additional Context

No response

mProjectsCode commented 1 day ago

Not without the use of some JavaScript.

E.g. you could create a code block with the language meta-bind-js-view.

{status} as status
---
if (context.bound.status === "Backlog") {
  return engine.markdown.create("button config 1 here");
} else if (context.bound.status === "InProgress") {
  return engine.markdown.create("button config 1 here");
}
// and so on...
PippoGot commented 1 day ago

I was also about to ask for something similar for views. Will try the code snippet.

PippoGot commented 1 day ago

In my case, I'd like to show some text based on the state of a boolean property, i.e. if true show the text while if false don't show the text. I tried to modify the code like this:

{property} as bool
---
if (context.bound.bool === true) {
  return engine.markdown.create(`VIEW[text]`);
} 

but I'm not sure on how to properly modify it. An example of this in the advanced use cases would be neat!

sanyam commented 23 hours ago

Thank you very much i will do with js. But i meant the feature like this:

label: "In Progress"
hidden: !(status === "Backlog" OR status === "Blocked")
id: "status-to-inprogress"
style: primary
actions:
  - type: updateMetadata
    bindTarget: status
    value: 'In Progress'

it will be more convenient for the cases like this to put condition in template. Or even more better (i don' know if it possible) inline like this

`BUTTON[status-to-inprogress, hidden: !(status === "Backlog" OR status === "Blocked") ]
mProjectsCode commented 22 hours ago

No, this will not be supported in the foreseeable future.

sanyam commented 21 hours ago

ok. thank you. Your plugin are awesome.