You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the only way to do input validation on LineEdits and TextEdits is to set the input-type property, but it's pretty limited.
I can think of three different ways to handle this:
A callback: validate(string, int) -> bool which would take the character added (or string pasted) and the position where it's being added and return true if it should be accepted, false otherwise. It would need to be called every time a character is entered (after input-type validation?) and when a string is pasted in.
A regex field that would be matched against every time a character is entered or a string is pasted. If the match fails, the change is refused.
The existing edited(string) callback could be called before the change instead of after, and take a boolean return value which would dictate whether or not the change is accepted. This is probably the least preferable one, since there would be no easy way to know what changed, and where.
Some use cases for this: A field that only allows numbers in a specific base. A field with a maximum length. Preventing the use of specific characters, such as non-ascii.
This would allow input validation directly when editing the LineEdit rather than when pressing some accept button later, resulting in a better user experience.
If time is an issue, I can contribute it, just let me know if/how you want it done.
The text was updated successfully, but these errors were encountered:
I'd suggest to take the entire string and the cursor position though in that validate call. We should also provide some standard validators (int, float, regexp, etc.).
I'm going to close this issue as Duplicate of #4288
I think a validate(string)->bool that pass the full string. But it might be a bit more complicated that that since we might want to allow "incomplete" input. Example, if i want to enter a date, "12/07/" should be allowed as you're typing the date.
Currently, the only way to do input validation on LineEdits and TextEdits is to set the input-type property, but it's pretty limited.
I can think of three different ways to handle this:
validate(string, int) -> bool
which would take the character added (or string pasted) and the position where it's being added and return true if it should be accepted, false otherwise. It would need to be called every time a character is entered (after input-type validation?) and when a string is pasted in.edited(string)
callback could be called before the change instead of after, and take a boolean return value which would dictate whether or not the change is accepted. This is probably the least preferable one, since there would be no easy way to know what changed, and where.Some use cases for this: A field that only allows numbers in a specific base. A field with a maximum length. Preventing the use of specific characters, such as non-ascii.
This would allow input validation directly when editing the LineEdit rather than when pressing some accept button later, resulting in a better user experience.
If time is an issue, I can contribute it, just let me know if/how you want it done.
The text was updated successfully, but these errors were encountered: