Esempio n. 1
0
    def test_radio_button(self):
        eq_(
            radio("people", "justin"),
            u'<input id="people_justin" name="people" type="radio" value="justin" />'
        )

        eq_(
            radio("num_people", 5),
            u'<input id="num_people_5" name="num_people" type="radio" value="5" />'
        )

        eq_(
            radio("num_people", 5),
            u'<input id="num_people_5" name="num_people" type="radio" value="5" />'
        )

        eq_(
            radio("gender", "m") + radio("gender", "f"),
            u'<input id="gender_m" name="gender" type="radio" value="m" /><input id="gender_f" name="gender" type="radio" value="f" />'
        )

        eq_(
            radio("opinion", "-1") + radio("opinion", "1"),
            u'<input id="opinion_-1" name="opinion" type="radio" value="-1" /><input id="opinion_1" name="opinion" type="radio" value="1" />'
        )

        eq_(
            radio("num_people", 5, checked=True),
            u'<input checked="checked" id="num_people_5" name="num_people" type="radio" value="5" />'
        )
Esempio n. 2
0
 def render(self, **kwargs):
     html = ''
     checked = kwargs['options'][0][1]
     for label, value in kwargs['options']:
         r = tags.radio(self.name, value, checked=value == checked)
         t = HTML.tag('span', c=label)
         l = HTML.tag('label', c=r+' '+t)
         html += HTML.tag('li', c=l)
     return HTML.tag('ul', class_='inputs-list', c=html)
Esempio n. 3
0
    def radio(self, name, value=None, checked=False, label=None, **attrs):
        """
        Outputs radio input.
        """
        try:
            checked = unicode(traverse_object_for_value(self.form.data, name)) == unicode(value)
        except (KeyError, AttributeError):
            pass

        return tags.radio(name, value, checked, label, **attrs)
Esempio n. 4
0
def select_radio(name, title, options, selected=[], help_text=None, **kwargs):
    expl = None
    if help_text is not None:
        expl = HTML.span(class_='helpText', c=help_text)

    radios = []
    for value, label in options:
        checked = value in selected
        radios.append(radio(name, value, checked, label, **kwargs))

    return HTML.div(class_='formField',
                    id='%s-field' % name,
                    c=[HTML.label(for_=name, c=[
                    HTML.span(class_='labelText', c=[title]),
                    HTML.span(class_='radioField', c=radios)]),
                       HTML.literal('<form:error name="%s" />' % name),
                       expl])
 def radio(self, name, value=None, checked=False, label=None, **attrs):
     """
     Outputs radio input.
     """
     checked = self.value(name) == value or checked
     return tags.radio(name, value, checked, label, **attrs)
Esempio n. 6
0
 def radio(self, name, value=None, checked=False, label=None, **attrs):
     """
     Outputs radio input.
     """
     checked = self.data.get(name) == value or checked
     return tags.radio(self.prefix + name, value, checked, label, **attrs) + self.getErrorTag(name)
Esempio n. 7
0
 def radio(self, name, value=None, checked=False, id=None, **attrs):
     checked = self.value(name) == value or checked
     return tags.radio(name, value, checked, label, **attrs)
Esempio n. 8
0
def radio_button(name, *args, **options):
    _update_fa(options, name)
    return radio(name, *args, **options)