silverbulletmd / silverbullet

The knowledge tinkerer's notebook
https://silverbullet.md
MIT License
2.43k stars 173 forks source link

Make filterbox return the typed value #992

Open montarion opened 2 months ago

montarion commented 2 months ago

I'd like to be able to type a new value into a filterbox, that isn't one of the supplied options. Sort of a combination between filterbox and prompt.

Use case: I use a filterbox to choose a category, and I'd like to be able to create a new category in that same step without having to create the category separately.

image

zefhemel commented 2 months ago

Implementation hint (likely for myself), the FilterList component already has a allowNew and newHint option, these could just be exposed to the filterBox API to achieve this result.

That way you could e.g. specify (API to be decided) something along the lines of filterBox("Category picker", [...], "Select your category", "Category name", "Create category")

That latter argument, when specified, would add a second choice to the list matching the exact filter phrase with a "Create category" button/hint next to it, just like the Page Picker does (with "Create page"). Would that do what you're looking for?

montarion commented 2 months ago

It would(and is probably better for consistency), but doesn't quite match what I was thinking. In my head you'd just receive the value back regardless of if it was picked as an option, or typed.

So you'd always at the very least have {"name": [chosen value]}

No need for an extra argument, just return what's in the textbox(if there aren't any choices left of course)