I'm looking for a way to change the width of the input box in a Django form.
The model code for a parameter looks like this:
my_integer = models.IntegerField('Window', default=50)
And, putting it into a form, the HTML code that is generated is this:
<input id="id_my_integer" name="my_integer" value="50" type="number">
And, the box is quite wide - maybe 20 characters.
If I add the code in the definition of the form class Meta:
widgets = {
'my_integer': forms.TextInput(attrs={'size':'3', 'maxlength':'3'}),
}
I get a box that is 5-6 characters wide that lets me insert 3 characters and the HTML code changes the type to type='text' and the increment/decrement arrows disappear.
So, what I really want is a 3 character wide box, with a 3 character input limit, having the NumberInput
widget's increment/decrement arrows. How do I do this?