Permalink
Browse files

Update AppendedWidget to bootstrap-2.0.2 and add PrependedWidget and

AppendPrependWidget

Also allow 'append_text' and 'prepend_text' to empty to fail more
gracefully.
  • Loading branch information...
1 parent 308148d commit 803776541eea4fbd15232e38940c2888356c72e4 @saschpe saschpe committed Mar 31, 2012
@@ -1,12 +1,14 @@
-<div class="control-group input-append{% if errors %} error{% endif %}">
+<div class="control-group{% if errors %} error{% endif %}">
<label class="control-label" for="{{ bf_raw.id_for_label }}">{{ label }}</label>
<div class="controls">
- {{ bf }}
- {% if errors %}
- <span class="help-inline">{{ errors }}</span>
- {% endif %}
- {% if help_text %}
- <p class="help-block">{{ help_text }}</p>
- {% endif %}
+ <div class="input-append">
+ {{ bf }}
+ {% if errors %}
+ <span class="help-inline">{{ errors }}</span>
+ {% endif %}
+ {% if help_text %}
+ <p class="help-block">{{ help_text }}</p>
+ {% endif %}
+ </div>
</div>
</div>
@@ -0,0 +1,15 @@
+<div class="control-group{% if errors %} error{% endif %}">
+ <label class="control-label" for="{{ bf_raw.id_for_label }}">{{ label }}</label>
+ <div class="controls">
+ <div class="input-append input-prepend">
+ {{ bf }}
+ {% if errors %}
+ <span class="help-inline">{{ errors }}</span>
+ {% endif %}
+ {% if help_text %}
+ <p class="help-block">{{ help_text }}</p>
+ {% endif %}
+ </div>
+ </div>
+</div>
+
@@ -0,0 +1,14 @@
+<div class="control-group{% if errors %} error{% endif %}">
+ <label class="control-label" for="{{ bf_raw.id_for_label }}">{{ label }}</label>
+ <div class="controls">
+ <div class="input-prepend">
+ {{ bf }}
+ {% if errors %}
+ <span class="help-inline">{{ errors }}</span>
+ {% endif %}
+ {% if help_text %}
+ <p class="help-block">{{ help_text }}</p>
+ {% endif %}
+ </div>
+ </div>
+</div>
View
@@ -1,4 +1,4 @@
-from django.forms.widgets import RadioInput, RadioFieldRenderer, RadioSelect,TextInput
+from django.forms.widgets import Input, RadioInput, RadioFieldRenderer, RadioSelect, TextInput
from django.utils.html import conditional_escape
from django.utils.encoding import force_unicode
from django.utils.safestring import mark_safe
@@ -25,6 +25,25 @@ def render(self):
class OptionsRadio(RadioSelect):
renderer = OptionsRadioRenderer
+
class AppendedText(TextInput):
def render(self, name, value, attrs=None):
- return '%s<span class="add-on">%s</span>' % (super(AppendedText,self).render(name, value, attrs),self.attrs['append_text'])
+ append_text = self.attrs.get('append_text', '')
+ return '%s<span class="add-on">%s</span>' % (super(AppendedText, self).render(name, value, attrs),
+ append_text)
+
+
+class PrependedText(TextInput):
+ def render(self, name, value, attrs=None):
+ prepend_text = self.attrs.get('prepend_text', '')
+ return '<span class="add-on">%s</span>%s' % (prepend_text, super(PrependedText, self).render(name, value, attrs))
+
+
+class AppendPrependText(TextInput):
+ def render(self, name, value, attrs=None):
+ append_text, prepend_text = self.attrs.get('append_text', ''), self.attrs.get('prepend_text', '')
+ return '<span class="add-on">%s</span>%s<span class="add-on">%s</span>' % (prepend_text, super(AppendPrependText, self).render(name, value, attrs), append_text)
+
+
+class EmailInput(Input):
+ input_type = 'email'

0 comments on commit 8037765

Please sign in to comment.