slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
16.93k stars 565 forks source link

TextInput: Input validation #4288

Open hunger opened 8 months ago

hunger commented 8 months ago

We should have a simple way to have common input validation on input.

Common things like "number", "float", "time" and maybe something pattern-based would be nice to have.

Currently you can work around this using the edited() and accepted() callbacks, but that is not very convenient nor designer-friendly.

(Originate from https://github.com/slint-ui/slint/discussions/4154)

hunger commented 8 months ago

This would improve on the InputType hack in #3356.

Enyium commented 20 hours ago

Since these use cases are often associated with specific data types that one would want to two-way-bind to, I believe dedicated widgets would be more appropriate. I talked about IntEdit and FloatEdit here.

In my app, I implemented a rudimentary version of a DurationEdit with an in-out property <duration> value. It allows for colon-separated integers with up to two colons. Values >= a day are represented using an hour value >= 24.

My widget also has an out property <string> unit that you can bind to to display the appropriate SI (or SI-near) unit to the right of the widget (i.e., s, min, or h). This is the unit of the leftmost number.

I want to recommend that a DurationEdit should be one of the dedicated text input widgets.