Opened 2 months ago

Closed 2 months ago

#35435 closed Uncategorized (duplicate)

NumberInput off-by-one on min value for type range

Reported by: mitch99 Owned by: nobody
Component: Forms Version: 5.0
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Follow-up to #35433 which was closed (and I couldn't reopen):

class ContentProfileDefinitionForm(forms.ModelForm):
    class Meta:
        model = ContentProfileDefinition
        fields = ["other", "weight"]
        widgets = {
            "weight": forms.NumberInput(
                attrs={
                    "type": "range",
                    "step": "1",
                    "min": "1",
                    "max": "5",
                }
            ),
        }

class ContentProfileDefinition(models.Model):
    other = models.ForeignKey("Other", on_delete=models.CASCADE)
    weight = models.PositiveSmallIntegerField(
        default=1,
        help_text="Weight",
        validators=[
            MinValueValidator(1),
            MaxValueValidator(5),
        ],
    )

I expect the min value on the range input to be 1, but it's actually 0:

<input type="range" name="form-2-weight" value="3" step="1" min="0" max="5" aria-describedby="id_form-2-weight_helptext" id="id_form-2-weight">

Change History (1)

comment:1 by mitch99, 2 months ago

Resolution: duplicate
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top