Comments (5)
This applies to RadioSelect as well.
templates/bootstrap_toolkit/field_choices.html
is as follows:
<input type="{{ type }}" name="{{ field.html_name }}" value="{{ choice_id }}"{% if type == "checkbox" %}{% if choice_id in field.value %} checked{% endif %}{% else %}{% if choice_id == field.value %} checked{% endif %}{% endif %}>
oddly enough, choice_id and field.value ARE in fact the same (you can output these in your form to verify this) but
if choice_id == field.value
evaluates to False for some reason. I'm not sure if this is a type issue?
from django-bootstrap-toolkit.
I'll check it out, thanks
Sent from my iPhone
Op 15 aug. 2012 om 10:42 heeft Gabe Jackson [email protected] het volgende geschreven:
This applies to RadioSelect as well.
templates/bootstrap_toolkit/field_choices.html
is as follows:oddly enough, choice_id and field.value ARE in fact the same (you can output these in your form to verify this) but if choice_id == field.value evaluates to False for some reason. I'm not sure if this is a type issue?
โ
Reply to this email directly or view it on GitHub.
from django-bootstrap-toolkit.
Ok, the problem is indeed the types. Changing the condition in fields_choices.html to:
{% if choice_id|safe in field.value|safe %} checked{% endif %}{% else %}{% if field.value|safe == choice_id|safe %} checked{% endif %}
solves the problem. Django usually does this unicode forcing in forms/widgets.py:
class RadioInput(SubWidget):
"""
An object used by RadioFieldRenderer that represents a single
<input type='radio'>.
"""
def __init__(self, name, value, attrs, choice, index):
self.name, self.value = name, value
self.attrs = attrs
self.choice_value = force_unicode(choice[0])
self.choice_label = force_unicode(choice[1])
self.index = index
def __unicode__(self):
return self.render()
def render(self, name=None, value=None, attrs=None, choices=()):
name = name or self.name
value = value or self.value
attrs = attrs or self.attrs
if 'id' in self.attrs:
label_for = ' for="%s_%s"' % (self.attrs['id'], self.index)
else:
label_for = ''
choice_label = conditional_escape(force_unicode(self.choice_label))
return mark_safe(u'<label%s>%s %s</label>' % (label_for, self.tag(), choice_label))
def is_checked(self):
return self.value == self.choice_value
def tag(self):
if 'id' in self.attrs:
self.attrs['id'] = '%s_%s' % (self.attrs['id'], self.index)
final_attrs = dict(self.attrs, type='radio', name=self.name, value=self.choice_value)
if self.is_checked():
final_attrs['checked'] = 'checked'
return mark_safe(u'<input%s />' % flatatt(final_attrs))
from django-bootstrap-toolkit.
fixed in #26
from django-bootstrap-toolkit.
Fix merged and uploaded to pypi, thanks
from django-bootstrap-toolkit.
Related Issues (20)
- How to implement bootswatch HOT 6
- Password widget rendered with type of text HOT 6
- Performance issue : to many get_template() HOT 1
- Create and / or document the steps to customize the BootstrapDateInput widget
- Upgrade eternicode/bootstrap-datepicker HOT 4
- Input type date for BootstrapDateInput HOT 4
- required in forms
- Windows 7 - ImportError: No module named 'versionโ when importing SOAPpy HOT 1
- ValueError: read of closed file HOT 1
- Extraneous `.DS_Store` files installed HOT 2
- Is there a recommendation for how to implement a type-ahead HOT 3
- Non empty TEMPLATE_STRING_IF_INVALID breaks widgets output HOT 1
- Is Bootstrap 3 compatibility planned? HOT 1
- The demo_app works with Django 1.5 only due to quoted urls HOT 7
- Template error when TEMPLATE_DEBUG = True HOT 1
- datepicker in static? HOT 1
- JS and CSS loaded by @property not present when using template HOT 2
- Provide a template tag to output messages from the messages framework HOT 3
- Cannot load files from template_tag_url. HOT 3
- Work on migrating to Bootstrap 3. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-bootstrap-toolkit.