#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 Mariusz Felisiak, 20 months ago

Cc: Jacob Rief Kapil Bansal added
Component: UncategorizedForms
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

Thanks for the report! As far as I'm aware we should pass min_value to the StepValueValidator. Bug in 3a82b5f655446f0ca89e3b6a92b100aa458f348f.

comment:2 by Kapil Bansal, 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 Jacob Rief, 20 months ago

Owner: changed from nobody to Jacob Rief
Status: newassigned

comment:4 by Jacob Rief, 20 months ago

There is a patch: https://github.com/django/django/pull/16742

will be fixed in Django-5.0

comment:5 by Sarah Boyce, 20 months ago

Has patch: set
Last edited 20 months ago by Mariusz Felisiak (previous) (diff)

comment:6 by Mariusz Felisiak, 20 months ago

Needs documentation: set
Patch needs improvement: set

comment:7 by Jacob Rief, 18 months ago

Version: 4.1dev

pull request has been fixed for dev branch

comment:8 by Natalia Bidart, 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 Mariusz Felisiak, 18 months ago

Triage Stage: AcceptedReady for checkin

comment:10 by Mariusz Felisiak <felisiak.mariusz@…>, 17 months ago

Resolution: fixed
Status: assignedclosed

In 1fe0b16:

Fixed #34473 -- Fixed step validation for form fields with non-zero minimum value.

Note: See TracTickets for help on using tickets.
Back to Top