[Django] #28879: Widget NumberInput becomes text if you change size

49 views
Skip to first unread message

Django

unread,
Dec 3, 2017, 11:30:08 AM12/3/17
to django-...@googlegroups.com
#28879: Widget NumberInput becomes text if you change size
------------------------------------------------+------------------------
Reporter: Chris Davies-Barnard | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.11
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
I'm adjusting the width of some form fields because small integers such as
qty and price don't need to be 20 long and the following code results in
them becoming type = 'text' regardless.

models.DecimalField: {'widget': TextInput(attrs={'size':'7'})},
models.IntegerField: {'widget': NumberInput(attrs={'size':'3'})},

breaking other aspects. Sorry don't know if I need to add more detail
etc...

--
Ticket URL: <https://code.djangoproject.com/ticket/28879>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 4, 2017, 9:17:08 AM12/4/17
to django-...@googlegroups.com
#28879: Widget NumberInput becomes text if you change size
-------------------------------------+-------------------------------------
Reporter: Chris Davies- | Owner: nobody
Barnard |
Type: Uncategorized | Status: closed
Component: Uncategorized | Version: 1.11
Severity: Normal | Resolution: needsinfo

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => needsinfo


Old description:

> I'm adjusting the width of some form fields because small integers such
> as qty and price don't need to be 20 long and the following code results
> in them becoming type = 'text' regardless.
>
> models.DecimalField: {'widget': TextInput(attrs={'size':'7'})},
> models.IntegerField: {'widget': NumberInput(attrs={'size':'3'})},
>
> breaking other aspects. Sorry don't know if I need to add more detail
> etc...

New description:

I'm adjusting the width of some form fields because small integers such as
qty and price don't need to be 20 long and the following code results in
them becoming type = 'text' regardless.
{{{
models.DecimalField: {'widget': TextInput(attrs={'size':'7'})},
models.IntegerField: {'widget': NumberInput(attrs={'size':'3'})},
}}
breaking other aspects. Sorry don't know if I need to add more detail
etc...

--

Comment:

I guess you're putting those lines in a `ModelAdmin.formfield_overrides`?
I tried this and couldn't reproduce the problem. Please reopen if you can
provide a sample project or a test case that demonstrates the problem.

--
Ticket URL: <https://code.djangoproject.com/ticket/28879#comment:1>

Django

unread,
Dec 4, 2017, 9:52:32 AM12/4/17
to django-...@googlegroups.com
#28879: Widget NumberInput becomes text if you change size
-------------------------------------+-------------------------------------
Reporter: Chris Davies- | Owner: nobody
Barnard |
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.11
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Chris Davies-Barnard):

* status: closed => new
* resolution: needsinfo =>


Comment:

Hi Tim,

Yes, more information below. My javascript call that relied on
type=number worked using the model as described but once I included the
formfield_overrides it stopped because the inputs had become type=text.

{{{#!python
#Invoice Item Class
class MainInvoiceItem(models.Model):
id = models.AutoField(primary_key=True) # AutoField?
invoice = models.ForeignKey(MainInvoice, on_delete=models.CASCADE)
order = models.IntegerField('Order')
description = models.TextField('Description', max_length=1000)
qty = models.IntegerField('Qty')
price = models.DecimalField('Price', max_digits=7, decimal_places=2)
discount = models.DecimalField('Discount/Mark Up', max_digits=5,
decimal_places=2,default=0, )
vat = models.DecimalField('VAT', max_digits=4,
decimal_places=2,default=0, )
total = models.DecimalField('Total', max_digits=7, decimal_places=2)
created = models.DateTimeField('Created Date',auto_now_add=True)
modified = models.DateTimeField('Modified Date',auto_now=True)

class Meta:
db_table = 'main_invoice_items'
verbose_name = 'Item'
verbose_name_plural = 'Items'
ordering = ['order']
}}}

Presented as inline items in the MainInvoice admin view

{{{#!python
##### Invoice Admin #####
class InlineInvoiceItems(admin.TabularInline):
#form = IndicatorInlineForm
model = MainInvoiceItem
extra = 1
formfield_overrides = {


models.DecimalField: {'widget':
TextInput(attrs={'size':'7'})},
models.IntegerField: {'widget':

TextInput(attrs={'size':'3'})},
models.TextField: {'widget': Textarea(attrs={'rows':2,
'cols':90})},
}
}}}

This works - but you will note that the html now shows decimal or integer
fields created as type=number become type=text. This doesn't cause a
major problem unless you are trying to grab type=number with javascript
and want to avoid grabbing 'text' fields at the same time.

{{{
<td class="field-qty">
<input type="text" name="maininvoiceitem_set-0-qty" value="1"
id="id_maininvoiceitem_set-0-qty" size="3">
<td>
}}}

Hope this explains it better.

Chris

--
Ticket URL: <https://code.djangoproject.com/ticket/28879#comment:2>

Django

unread,
Dec 4, 2017, 10:14:46 AM12/4/17
to django-...@googlegroups.com
#28879: Widget NumberInput becomes text if you change size
-------------------------------------+-------------------------------------
Reporter: Chris Davies- | Owner: nobody
Barnard |
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.11
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Old description:

> I'm adjusting the width of some form fields because small integers such
> as qty and price don't need to be 20 long and the following code results
> in them becoming type = 'text' regardless.
> {{{
> models.DecimalField: {'widget': TextInput(attrs={'size':'7'})},
> models.IntegerField: {'widget': NumberInput(attrs={'size':'3'})},
> }}
> breaking other aspects. Sorry don't know if I need to add more detail
> etc...

New description:

I'm adjusting the width of some form fields because small integers such as
qty and price don't need to be 20 long and the following code results in
them becoming type = 'text' regardless.
{{{
models.DecimalField: {'widget': TextInput(attrs={'size':'7'})},
models.IntegerField: {'widget': NumberInput(attrs={'size':'3'})},
}}}
breaking other aspects. Sorry don't know if I need to add more detail
etc...

--

Comment (by Tim Graham):

Your steps to reproduce use `TextInput` not `NumberInput`.

--
Ticket URL: <https://code.djangoproject.com/ticket/28879#comment:3>

Django

unread,
Dec 4, 2017, 12:16:43 PM12/4/17
to django-...@googlegroups.com
#28879: Widget NumberInput becomes text if you change size
-------------------------------------+-------------------------------------
Reporter: Chris Davies- | Owner: nobody
Barnard |
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.11
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Chris Davies-Barnard):

Yes, apologies.

However, using NumberInput means the new size is not followed and the
fields return to their normal size.

So maybe this is a Django CSS issue?

--
Ticket URL: <https://code.djangoproject.com/ticket/28879#comment:4>

Django

unread,
Dec 4, 2017, 12:35:44 PM12/4/17
to django-...@googlegroups.com
#28879: Widget NumberInput becomes text if you change size
-------------------------------------+-------------------------------------
Reporter: Chris Davies- | Owner: nobody
Barnard |
Type: Uncategorized | Status: closed
Component: Uncategorized | Version: 1.11
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed

* resolution: => invalid


Comment:

According to [https://stackoverflow.com/questions/22709792/html-input-
type-number-wont-resize a stackoverflow question], `input[type=number]`
does not support the `size` attribute.

--
Ticket URL: <https://code.djangoproject.com/ticket/28879#comment:5>

Django

unread,
Dec 4, 2017, 1:17:20 PM12/4/17
to django-...@googlegroups.com
#28879: Widget NumberInput becomes text if you change size
-------------------------------------+-------------------------------------
Reporter: Chris Davies- | Owner: nobody
Barnard |
Type: Uncategorized | Status: closed
Component: Uncategorized | Version: 1.11
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Chris Davies-Barnard):

Thanks Tim.

Sorry - Brain fade and tiredness left me unable to think beyond the
obvious.

Its a shame for the inconsistency!

Chris

--
Ticket URL: <https://code.djangoproject.com/ticket/28879#comment:6>

Reply all
Reply to author
Forward
0 new messages