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.
* 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>
* 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>
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>
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>
* 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>
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>