DurationField component to edit java.time.Duration

For one of my WIP demo apps, I needed a field for java.time.Duration. This was not the first time I implemented a field for this type (and I’d bet other have implemented it as well into their projects), so I decided to polish it to add-on quality. Also served my tutorial project related to CustomField component (this is coming out soonish).

Built it pretty much around TextField. And yes, arguably one could “simply do it with a converter”, but I find this kind of fields cleaning up my code quite a bit. Here is the feature list:

  • Support “basic field features”: label, required indicator, tooltip etc.
  • Human friendly lenient formatting, “hh:mm:ss” as default, but also supports hhmm (without colon) for quick inputting and ISO8601 (for human compilers🤪). Parsing and formatting logic are defined in protected methods for possible customization.
  • Some built-in validation to guide users towards proper formatting.
  • Constructor with a label (this also comes with pretty much all core Vaadin components, good for API consistency).
  • A “proxy” for the input prompt, as this simple field happens to be based on TextField.
  • Defaulting to use “lazy value changes mode” by default and proxying related methods to the underlying TextField. I like desktop-application-like forms where validation errors (and fixes) are shown on-the-fly without triggering validation by clicking the save button.

Dropped the implementation to Viritin add-o, ships in: in.virit:viritin:2.8.12. Enhancments and bugreports here or directly to GitHub.

Online demo here:
https://addons.dokku1.parttio.org/formfields

2 Likes