-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix DateEntry Validator overwrite #5866
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
base: develop
Are you sure you want to change the base?
Conversation
// this also the format in which date srtings are passed to the validator. | ||
// | ||
// Since: TODO: I am unsure what to put here. | ||
func (e *DateEntry) DateFormat() string { |
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.
I think this makes more sense to be a new public API on the fyne.Locale
type, rather than on Entry. And FYI the Since line would be // Since: 2.7
in this case, since 2.7 will be the next feature release of Fyne
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.
I agree that it makes more sense. However, the logic that I call for that method is in the widget package (under widget/locale.go). I can move the logic to the root fyne package, which would also improve fyne's current locale functionality. I just didn't want to take the liberty to make architectural decisions like that.
I'm unclear why the new For clarity can you describe the original issue that this PR is resolving? Thanks for the contribution :) |
The original issue I had was that I couldn't clear the DateEntry without the default validator invalidating the field. This meant that I could not make an optional date input. I also have the need to check that the date is after a certain point in time. I can think of more examples, there are probably infinite use cases for custom date validation. I was surprised when I couldn't just set the Validator field on the DateEntry and have that validator be used. Which is why I consider this to be a bug. The user code needs to know which DateFormat the input is using, in order to parse the string which is passed to the Validator. The string needs to be parsed so that we can then run checks on the date which the user supplied. Another solution to this could be ad a Validator kind of field that takes in a |
Yup, let's get that fixed for sure.
Isn't that possible with the builtin validator?
This is a side-effect of replacing the validator - if you call the builtin one it won't be required.
Yes, that should be resolved as well - but you could chain your new validator on top of the old one... |
It feels like I am missing something crucial in how to use the Validator.
Not in a way that I could figure out. As far as I know, the default Validator just checks whether it can parse the input to a date, and returns an error if it can't.
I am not sure about how I would go about achieving this. The old Validator is instantiated as part of CreateRenderer. |
Oh on reflection, I see you meant that you wanted to validate that the parsed date is after some date. I didn't get that before.
Fair, I missed that. You can call |
Description:
I changed the validation behaviour of DateEntry, so that the default Validator is only set if the user code does not provide it's own Validator
As part of this change:
DateFormat()
function, allowing user code to know which date format is being used. This is useful for validation.Fixes #5865
Checklist:
* gofmt and goimport passes without any changes. I am not sure which linter to use, but my editor is set up to use gopls for pretty much everything
Where applicable:
** I added a function name
DateFormat
to DateEntry. I am not sure what I should put in the Since tag?*** I changed the way the default Validator works for DateEntry. I am happy to revert this if it is considered to be a breaking change.