-
Is it possible to change the suggestion list of an Input's suggester as the user types? For example, like below: def on_input_changed(self, event: Input.Changed) -> None:
if event.value and event.value[-1] == '/':
event.input.suggester=SuggestFromList(os.listdir(event.value), case_sensitive=False) The goal is every time the user writes a '/' they get suggestions from the available files in the path they have specified so far. When I tried it seemed that the suggester cannot be changed this way. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Rather than attempt to change the suggester on the fly like that, it would make more sense for you to implement a filesystem content suggester, implementing your own If it helps, while it isn't for a similar result, here's some code where I wrote my own suggester that suggests tags for a tag input field, taking into account tags that have already been used, etc. |
Beta Was this translation helpful? Give feedback.
I wouldn't get too caught up in how that happens; I was showing more the pattern for how you'd subclass the base class and implement your own
get_suggestion
. A suggester for a filesystem should be pretty straightforward; remember thatget_suggestion
each time there's a change to theInput
, so you should only need take the value it passes, parse out the directory part (nice and easy if you usepathlib.Path
for example), and then return the best suggestion from within that directory.