-
Hi! I'm wondering what would be a good option for applying a regular expression/pattern match to a textedit, so that users can't enter text other than that allowed? I think I could do this by checking the response for changed(), but in that case there's a slight flicker because presumably there's a frame where the text is changed, before I revert it to the last permitted state. I can live with the flicker, but interested to know if there's a better approach. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
There are two situations to consider:
For the first case, I think we should add a filter to what characters For the second case, I think it is better to leave the validation to the egui user. How to respond to invalid input depends highly on the situation - sometimes you want to color the |
Beta Was this translation helpful? Give feedback.
-
Hi, thanks for answering! My situation is a bit more complex, like the email case (in my case, ensuring, e.g., that money entered has no more than one decimal). I could do the validation and provide an error rather than prohibit invalid input. I think that's a great approach that would work with egui in its current form. Thinking about changes to egui, I had been thinking of a way to pass a regular expression to |
Beta Was this translation helpful? Give feedback.
-
Ah, maybe I misunderstood the filter option. So the user would provide a function of the form |
Beta Was this translation helpful? Give feedback.
There are two situations to consider:
For the first case, I think we should add a filter to what characters
TextEdit
accepts, i.e. just aFn(char) -> bool
passed to one of theTextEdit
builder functions. If the users tried to enter characters outside this filter, they won't be accepted.For the second case, I think it is better to leave the validation to the egui user. How to respond to invalid input depends highly on the situation - sometimes you want to color the
TextEdit
red, or show an error text next to it.