Anybody remembers a handy window.prompt JS API?

Anybody remembers a handy window.prompt JS API? Haven’t seen that lately much in any web apps. A similar pattern is fairly straightforward to replicated with Vaadin Dialog, TextField and couple of buttons, but I recently, partly for fun, created a Java API for it and dropped it to Viritin add-on. To my surprise it fits farily well to Lumo theme :sunglasses:

The trigger for it was a hobby related app I was recently building. I noticed I had used Window (in Vaadin 7) + components in similar manner I expect quite many Vaadin users to do it, but that’s a lot of code just to get a short string or number input from the user.

The biggest discovery in this stunt for me was that the CompletableFuture, dispite its largish API, is actually quite decent interface to use for this kind of generic helpers requiring asynchronouse waiting of user :thinking: For more domain specific classes (like in-app re-usable components) I’d maybe create custom interfaces still.

Somebody (or an AI bot :thinking:), was recently “spamming” our quickstart with a CLI based “Guess a number game” Java code. I answerd him with a Vaadin version created by ChatGPT​:sunglasses: I was bit dissapointed the CLI version was shorter, so I applied this helper to it and now it is pretty much the same length. Also, the game logic is more present than from the ChatGPT generated variant. Maybe it gives some inspiration for your API design :man_shrugging:

BTW. How would you think of non browser API based versions of similar helpers? Ones built with Dialog + basic Vaadin components so that they would be easier to theme. Somthing like Promp.promptDouble, Promp.promptLocalDate, Promp.promptString… They could also be implemented to contains some more validation than this quick draft for the JS API.

1 Like

You can check the ChatGPT version from the docs for a reference: Vaadin Flow Quick Start