-
Notifications
You must be signed in to change notification settings - Fork 263
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
Feature: Validate Input #167
Conversation
ad414d7
to
edb33a0
Compare
runes := []rune(s) | ||
if m.CharLimit > 0 && len(runes) > m.CharLimit { | ||
m.value = runes[:m.CharLimit] | ||
} else { | ||
m.value = runes | ||
} | ||
if m.pos == 0 || m.pos > len(m.value) { | ||
if (m.pos == 0 && len(m.value) == 0) || m.pos > len(m.value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @maaslalani do you know if this was intended?
Basically now when I use SetValue
to prefill a field my cursor is no longer moved to the end of the line and I have to call CursorEnd
myself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey! That's definitely a bug, I will fix it soon! Thank you for catching it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, if you want I can open a PR 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you would like to, go for it! It would be much appreciated :)
This PR builds upon the excellent work in charmbracelet#167 and charmbracelet#114 and adds a bit more customizability to the feature. Currently, the validation API will completely block text input if the Validate function returns an error. This commit makes this behavior configurable by introducing a ValidateAction which decides how to proceed in case a validation error happens. To preserve backwards compatibility, the default behavior remains unchanged. If ValidateAction is set to AllowInput, the text input error will still be set if needed, but actual input will not be blocked. This is helpful for cases where the user is requested to type an existing system path, and the Validate function keeps asserting this. With the current implementation such a validation is not possible. For example: > / Err: nil > /t Err: /t: No such file or directory > /tm Err: /tm: No such file or directory > /tmp Err: nil
This PR builds upon the excellent work in charmbracelet#167 and charmbracelet#114 and adds a bit more customizability to the feature. Currently, the validation API will completely block text input if the Validate function returns an error. This commit makes this behavior configurable by introducing a ValidateAction which decides how to proceed in case a validation error happens. To preserve backwards compatibility, the default behavior remains unchanged. If ValidateAction is set to AllowInput, the text input error will still be set if needed, but actual input will not be blocked. This is helpful for cases where the user is requested to type an existing system path, and the Validate function keeps asserting this. With the current implementation such a validation is not possible. For example: > / Err: nil > /t Err: /t: No such file or directory > /tm Err: /tm: No such file or directory > /tmp Err: nil
This PR builds upon the excellent work in charmbracelet#167 and charmbracelet#114 and adds a bit more customizability to the feature. Currently, the validation API will completely block text input if the Validate function returns an error. This commit makes this behavior configurable by introducing a ValidateAction which decides how to proceed in case a validation error happens. To preserve backwards compatibility, the default behavior remains unchanged. If ValidateAction is set to AllowInput, the text input error will still be set if needed, but actual input will not be blocked. This is helpful for cases where the user is requested to type an existing system path, and the Validate function keeps asserting the existence of the path. With the current implementation such a validation is not possible. For example: > / Err: nil > /t Err: /t: No such file or directory > /tm Err: /tm: No such file or directory > /tmp Err: nil
This PR builds upon the excellent work in charmbracelet#167 and charmbracelet#114 and adds a bit more customizability to the feature. Currently, the validation API will completely block text input if the Validate function returns an error. This commit makes this behavior configurable by introducing a ValidateAction which decides how to proceed in case a validation error happens. To preserve backwards compatibility, the default behavior remains unchanged. If ValidateAction is set to AllowInput, the text input error will still be set if needed, but actual input will not be blocked. This is helpful for cases where the user is requested to type an existing system path, and the Validate function keeps asserting the existence of the path. With the current implementation such a validation is not possible. For example: > / Err: nil > /t Err: /t: No such file or directory > /tm Err: /tm: No such file or directory > /tmp Err: nil
This PR builds upon the excellent work in charmbracelet#167 and charmbracelet#114 and adds a bit more customizability to the feature. Currently, the validation API will completely block text input if the Validate function returns an error. This commit makes a breaking change to the ValidateFunc by returning an additonal bool that indicates whether or not input should be blocked. This is helpful for cases where the user is requested to type an existing system path, and the Validate function keeps asserting the existence of the path. With the current implementation such a validation is not possible. For example: > / Err: nil > /t Err: /t: No such file or directory > /tm Err: /tm: No such file or directory > /tmp Err: nil
This PR builds upon the excellent work in charmbracelet#167 and charmbracelet#114 and adds a bit more customizability to the feature. Currently, the validation API will completely block text input if the Validate function returns an error. This commit makes a breaking change to the validate API to no longer block input if this is the case, thus handing this responsibility to the clients. This is helpful for cases where the user is requested to type an existing system path, and the Validate function keeps asserting the existence of the path. With the current implementation such a validation is not possible. For example: > / Err: nil > /t Err: /t: No such file or directory > /tm Err: /tm: No such file or directory > /tmp Err: nil
This PR builds upon the excellent work in charmbracelet#167 and charmbracelet#114 and makes a breaking change to the validation API. Currently, validation will completely block text input if the Validate function returns an error. This is now changed so the function no longer blocks input if this is the case, thus handing this responsibility to the clients. This is helpful for cases where the user is requested to type an existing system path, and the Validate function keeps asserting the existence of the path. With the current implementation such a validation is not possible. For example: > / Err: nil > /t Err: /t: No such file or directory > /tm Err: /tm: No such file or directory > /tmp Err: nil
This PR builds upon the excellent work in charmbracelet#167 and charmbracelet#114 and makes a breaking change to the validation API. Currently, validation will completely block text input if the Validate function returns an error. This is now changed so the function no longer blocks input if this is the case, thus handing this responsibility to the clients. This is helpful for cases where the user is requested to type an existing system path, and the Validate function keeps asserting the existence of the path. With the current implementation such a validation is not possible. For example: > / Err: nil > /t Err: /t: No such file or directory > /tm Err: /tm: No such file or directory > /tmp Err: nil
* feat(textinput): do not block input on validation This PR builds upon the excellent work in #167 and #114 and makes a breaking change to the validation API. Currently, validation will completely block text input if the Validate function returns an error. This is now changed so the function no longer blocks input if this is the case, thus handing this responsibility to the clients. This is helpful for cases where the user is requested to type an existing system path, and the Validate function keeps asserting the existence of the path. With the current implementation such a validation is not possible. For example: > / Err: nil > /t Err: /t: No such file or directory > /tm Err: /tm: No such file or directory > /tmp Err: nil * fix: change name --------- Co-authored-by: Maas Lalani <maas@lalani.dev>
* feat(textinput): do not block input on validation This PR builds upon the excellent work in charmbracelet#167 and charmbracelet#114 and makes a breaking change to the validation API. Currently, validation will completely block text input if the Validate function returns an error. This is now changed so the function no longer blocks input if this is the case, thus handing this responsibility to the clients. This is helpful for cases where the user is requested to type an existing system path, and the Validate function keeps asserting the existence of the path. With the current implementation such a validation is not possible. For example: > / Err: nil > /t Err: /t: No such file or directory > /tm Err: /tm: No such file or directory > /tmp Err: nil * fix: change name --------- Co-authored-by: Maas Lalani <maas@lalani.dev>
Based on #114
Adds
Validate
property totextinput
to ensure input is valid.Validate is a function that accepts a
string
and returns anerror
which may benil
if the string is valid.