Opened 20 months ago
Closed 18 months ago
#34473 closed Bug (fixed)
StepValueValidator does not take into account min_value
Reported by: | James Meakin | Owned by: | Jacob Rief |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Jacob Rief, Kapil Bansal | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If you define a number input with <input type="number" min=1 step=2>
, client side this will only allow positive odd numbers.
We could generate the same input in a Django form with IntegerField(min_value=1, step_size=2)
and Field.localize
is False
, which would then use MinValueValidator
and StepValueValidator
.
We then get into a problem as StepValueValidator
always uses 0
as the base, so step_size=2
only even numbers are allowed. This then conflicts with the client side validation, and the user cannot submit any value for the input.
I'm unsure if this is a bug or whether this is just a configuration problem, apologies if so, but the behaviour does seem to me to conflict with how min and step is handled by browsers.
Change History (10)
comment:1 by , 20 months ago
Cc: | added |
---|---|
Component: | Uncategorized → Forms |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
comment:2 by , 20 months ago
Thanks for the report. I think this is a bug. We need to consider min value also with step_size
comment:3 by , 20 months ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 20 months ago
There is a patch: https://github.com/django/django/pull/16742
will be fixed in Django-5.0
comment:6 by , 20 months ago
Needs documentation: | set |
---|---|
Patch needs improvement: | set |
comment:8 by , 18 months ago
Needs documentation: | unset |
---|---|
Patch needs improvement: | unset |
Hello Jacob,
When the PR for this ticket is updated to the latest requests from reviewers, ideally you should unset the ticket's flags "needs documentation" and "patch needs improvement". That way, the PR will re-appear in the list of branches needing re-review. I have unset these for you now.
comment:9 by , 18 months ago
Triage Stage: | Accepted → Ready for checkin |
---|
Thanks for the report! As far as I'm aware we should pass
min_value
to theStepValueValidator
. Bug in 3a82b5f655446f0ca89e3b6a92b100aa458f348f.