Skip to content
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

Update middleware validator to handle only min value, add min value validations in various forms #1138

Merged
merged 2 commits into from
Mar 17, 2022

Conversation

ankurp-bst
Copy link
Contributor

  1. Updated the readMinMax function to handle empty max value so that only min value can be provided (for example: a field that requires positive number, hence min=0 and no max value). For this field the validation will be described as:
type Example struct {
    PositiveField int `valid:"0,"`
}

Here only min value (0) will be validated, and if negative value is entered, it will show an error:

Positive Field: should be at least 0
  1. Several forms on the control panel didn't have proper validations on the backend, this PR adds those validations.

@jo3-l
Copy link
Contributor

jo3-l commented Mar 15, 2022

Consider letting readMinMax return math.MaxFloat64 if there is no explicit maximum given, Then there will be no need to specially handle the case where there is no maximum.
Never mind; this doesn't simplify the code much at all. Disregard.

Comment on lines 223 to 230
onlyMin := false
min, _ := valid.Float(0)
max, _ := valid.Float(1)
if valid.values[1] == "" {
onlyMin = true
}

return min, max
return min, max, onlyMin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible to simplify this thusly: return min, max, valid.values[1] == "". Whether this is a good idea is debatable, but figured I'd throw it out there.

@ashishjh-bst ashishjh-bst merged commit 2323b53 into botlabs-gg:dev Mar 17, 2022
@ankurp-bst ankurp-bst deleted the positive-value-validation branch July 4, 2022 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants