boostrap prepend-input for widgets

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
class PrependWidget(Widget):
    u"""
    Widget that prepend boostrap-style span with data to specified base widget
    """

    def __init__(self, base_widget, data, *args, **kwargs):
        u"""Initialise widget and get base instance"""
        super(PrependWidget, self).__init__(*args, **kwargs)
        self.base_widget = base_widget(*args, **kwargs)
        self.data = data

    def render(self, name, value, attrs=None):
        u"""Render base widget and add bootstrap spans"""
        field = self.base_widget.render(name, value, attrs)
        return mark_safe((
            u'<div class="input-prepend">'
            u'    <span class="add-on">%(data)s</span>%(field)s'
            u'</div>'
        ) % {'field': field, 'data': self.data})

More like this

  1. boostrap append-input for widgets by DimmuR 8 months, 3 weeks ago
  2. RangeField and RangeWidget by marinho 4 years, 8 months ago
  3. Bootstrap button dropdown widget (replaces forms.Select) by benjaoming 10 months, 3 weeks ago
  4. Signal to post new saved objects to Twitter by arthurfurlan 4 years, 3 months ago
  5. Newforms customs validators by baptiste 6 years, 3 months ago

Comments

(Forgotten your password?)