Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ThomasWaldmann opened this issue Jan 6, 2012 · 3 comments
Labels
bug Something isn't working

Comments

@ThomasWaldmann
Copy link
Member

Original report by jek (Bitbucket: jek, GitHub: jek).


#!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" />
@ThomasWaldmann
Copy link
Member Author

Original comment by xiaq (Bitbucket: xiaq, GitHub: 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:

#!python

>>> [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//.

@ThomasWaldmann
Copy link
Member Author

Original comment by RogerHaase (Bitbucket: RogerHaase, GitHub: RogerHaase).


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>

@ThomasWaldmann
Copy link
Member Author

Original comment by xiaq (Bitbucket: xiaq, GitHub: xiaq).


Please review this patch: http://codereview.appspot.com/6637048

I decided to call the pseudo attribute "_for_value" to eliminate the possibility of name collisions with possible new HTML attributes in future.

@ThomasWaldmann ThomasWaldmann added major bug Something isn't working and removed major labels Oct 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant