Giter Club home page Giter Club logo

Comments (5)

gabejackson avatar gabejackson commented on August 26, 2024

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.

dyve avatar dyve commented on August 26, 2024

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.

gabejackson avatar gabejackson commented on August 26, 2024

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.

gabejackson avatar gabejackson commented on August 26, 2024

fixed in #26

from django-bootstrap-toolkit.

dyve avatar dyve commented on August 26, 2024

Fix merged and uploaded to pypi, thanks

from django-bootstrap-toolkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.