#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 <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/072.4ab8d15b69e63d9845ac5e4982bea8b3%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to