Question

In a Django 1.5 Application with django-bootstrap-toolkit, I want to have the following html result:

<div class="input-append">
    <input class="span2" type="number" id="offer_finance_vat" min="0" max="99" value="20">
    <span class="add-on">%</span>
</div>

Important are the appending "%" as well as type="number", min and max

Here is my Form code:

class FinanceForm(forms.Form):

    vat = forms.DecimalField(
        decimal_places=0,
        label="Value added tax",
        widget=BootstrapTextInput(append="%"),
        initial=0,
        min_value=0,
        max_value=99
    )

But in html type, min and max are missing then.

Is there also an opportunity to get a step="2" attribute?

Would this be possible with crispy-forms?

Was it helpful?

Solution

You can set the value of the widget.attrs to pass certain other HTML attributes to the form.

>>> from django import forms
>>> name = forms.TextInput(attrs={'size': 10, 'title': 'Your name',})
>>> name.render('name', 'A name')
u'<input title="Your name" type="text" name="name" value="A name" size="10" />'

-Django Docs

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top