-
Notifications
You must be signed in to change notification settings - Fork 815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Limit Input characters #3508
Comments
My two cents: HTML form inputs have a number of attributes that can be set. But this approach seems to be like the HTML version of the one ring to rule them all. I can just imagine the spaghetti code trying to implement all of the logic for that. In order to keep some concerns separate, I'd propose a number of higher level widgets that subclass the Input widget. I'm thinking more in line with how you can set a "type" for an html input. I.e. type="email", type="number" etc. Some widgets that correspond to those html input types could be a good solution. The benefit for developers using textual is that they don't have to roll their own solution to something commonly used. It also makes it very quick and clean to compose forms. Some ideas: An An A A A A Depending on the widget above, some other parameters could make sense. For example a NumberInput could take a maxlength, etc. There is also the Possibly related: with textual-web corresponding something like NumericInput to |
This would be a great feature. As part of limiting input characters, is it possible to add limits on input length. A use case would be for day/month/year fields. Also preventing input entirely. I have subclassed Input for this, and just blink the cursor if input prevented. Limiting characters would be a great addition as you can then deal with unwanted input as it happens, prior to validation. Would be good to be able to use a pattern (regex) to build an input that validates on a per key basis - you could then implement all of the above just based on different regexes. (except password) - the regex could also limit the length. |
Grabbing for initial option evaluation. |
A wee wander through some of the pre-existing approaches and things to consider. IntroductionI feel there's a couple of things that need to be considered with this, and that they often go hand-in-hand. Restricted inputs tend to also imply formatted inputs; the idea being that someone seldom wants to say "I want to only allow input of numbers" but instead wants to say "I want to allow entry of a floating point value up to 3 decimal places", etc; this would normally imply that they want to be able to say that the input should be of a specific format when the user types. Moreover, it's not uncommon to have the format characters (in the case of the decimal, it would be a Pre-existing approachesThis isn't exactly a novel problem; there are plenty of frameworks and the like out there that have solved this problem one way or another. Here I'll note the main approaches that seem to exist, from which we might take inspiration. xBase/Clipper
|
As a small followup to the notes above, prompted by this discussion popping up, this was one of the other benefits of the "picture" approach I mention above with the xBase family of languages: the formatting side of things took care of this (numeric inputs would align in the way you'd expect from a numeric input). |
Don't forget to star the repository! Follow @textualizeio for Textual updates. |
We need a way for Inputs to limit the characters they allow.
A classic use would be to have an Input that only allowed entering numbers.
Have a look at the browser input and see how its done there. Please propose a solution here before attempting.
The text was updated successfully, but these errors were encountered: