Issue #9 new

<label> for= generation needs to know about radio/checkbox id mangling

jason kirtland
repo owner created an issue

{{{

!python

from flatland import String from flatland.out.markup import Generator Schema = String.named('choice') html = Generator(auto_domid=True, auto_for=True) el = Schema('b') print html.label(el) <label for="f_choice" /> print html.input(el, type='radio', value='a') <input type="radio" name="choice" value="a" id="f_choice_a" /> print html.input(el, type='radio', value='b') <input type="radio" name="choice" value="b" checked="checked" id="f_choice_b" />

}}}

Comments (4)

  1. xiaq

    EDIT: remove comments about checkbox, as RogerHaase pointed out that it makes sense to have multiple checkboxes for one element (multivalues).

    I suggest something like this:

    >>> [same as above]
    >>> print html.label(el, value='a')
    <label for="f_choice_a" />
    >>> print html.input(el, type='radio', value='a')
    <input type="radio" name="choice" value="a" id="f_choice_a" />
    >>> print html.label(el, value='b')
    <label for="f_choice_b" />
    >>> print html.input(el, type='radio', value='b')
    <input type="radio" name="choice" value="b" checked="checked" id="f_choice_b" />
    

    This takes advantage of the fact that value is not a valid attribute for label tags. If it feels dirty (ie. that value might become a valid attribute for label tags) we can use something like _value or for_value.

  2. Roger Haase

    An alternative is to have a new method to produce an input element with a matching label:

    set myinput, mylabel = html.makeInputWithLabel(xxx...)

    then we could do:

    <dt> {{ mylabel }} </dt><dl> {{ myinput }} </dl>
    
  3. Log in to comment