I’ve been testing this further via console now. Not through my app, and without even rendering any template. It appears to have nothing to do with range controls: it happens for any model I use, but only for fields of PositiveIntegerField type specifically.
In my console:
from tradeapp.forms import TestForm
f = TestForm()
f
Output:
<tr><th><label for="id_num_items">Num items:</label></th><td><input type="number" name="num_items" value="0" min="0" max="5" id="id_num_items"></td></tr>
The form is defined as:
class TestForm(ModelForm):
class Meta:
model = Event
fields = ['num_items']
widgets = {
'num_items': NumberInput(attrs={'min': 1, 'max': 5})
}
This model is defined as:
class Event(models.Model):
num_items = models.PositiveIntegerField(default=1, blank=True)
Maybe there’s a chance that a some library is still lingering somewhere, but I don’t know how/why, since the bootstrap library is only involved in rendering to a template - which I’m not even getting as far as here.
(Edit: btw yes, I did remove bootstrap5 from my INSTALLED_APPS to run these tests.)
Could it be relevant that I’m using MySQL as a database backend??
It kind of makes sense that Django would attempt to enforce some sort of minimum of zero on PositiveIntegerFields …
I really appreciate your help so far btw!
Edit: Also interesting is the difference between these two console outputs on the same form object:
print(f.Meta.widgets['num_items'].attrs)
Output:
{'min': 1, 'max': 5}
and
print(f)
Output:
<tr><th><label for="id_num_items">Num items:</label></th><td><input type="number" name="num_items" value="0" min="0" max="5" id="id_num_items"></td></tr>