Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove up and down arrows from Django decimal ModelForm field

My decimal ModelForm fields are being displayed with an "up/down arrows" within the field that increases/descrease the field's values.

Any feedback on how I could remove/hide those arrows?

Form:

class PriceAssessment1Form(forms.ModelForm):
    class Meta:
        model = Component
        fields = ['size_height','size_width','size_length','weight','base_material_price']

Model

class Component(models.Model):

    name = models.CharField(max_length=255)
    created_date= models.DateTimeField(default=datetime.now)
    user = models.ForeignKey(User)
    price_assessment_started = models.BooleanField(default=False)

    size_height = models.DecimalField(null=True,blank=True, max_digits=9, decimal_places=2)
    size_width = models.DecimalField(null=True,blank=True, max_digits=9, decimal_places=2)
    size_length = models.DecimalField(null=True,blank=True, max_digits=9, decimal_places=2)

    weight = models.DecimalField(null=True,blank=True, max_digits=9, decimal_places=2)

    base_material_price = models.DecimalField(null=True,blank=True, max_digits=9, decimal_places=2)

Template

<form action="{% url 'portal_price_assessment' component_id %}" method="post"> {% csrf_token %}
            <div>
                <div>size_height {{ form.size_height }}</div>
                <div>size_width {{ form.size_width }}</div>
                <div>size_length {{ form.size_length }}</div>
                <div>weight {{ form.weight }}</div>
                <div>base_material_price {{ form.base_material_price }}</div>
             </div>
            <div style="margin-top:18px;">
                <a href="{% url 'portal_home' %}" class="btn btn-link">Cancel</a>
                <button class="btn" type="submit" >&nbsp;Save & Close</button>
            </div>
        </form>
like image 765
bbrooke Avatar asked Jan 11 '23 09:01

bbrooke


2 Answers

You can override the ModelForm field to use whatever widget you would prefer like so:

class AuthorForm(ModelForm):

    class Meta:
        model = Author
        fields = ('name', 'title', 'birth_date')
        widgets = {
            'name': TextInput(attrs={'placeholder': 'That dude cray'}),
        }
  • Example got from the django docs Overriding ModelForm fields
like image 93
parsenz Avatar answered Jan 16 '23 22:01

parsenz


I found the answer here: Can I hide the HTML5 number input’s spin box?

The "arrows" are called "spinners"

like image 43
bbrooke Avatar answered Jan 16 '23 22:01

bbrooke