I’m writing a wtforms custom form that consists of
-
multiple boolean check button / radio button
-
and a hidden text input.
-
if user clicks ‘other’ button, the textinput is enabled and user can manually write things
-
if user un-clicks ‘other’ button, the textinput is disabled.
here’s the widget function that draws this(for multiple checkboxes):
def select_multi_other_checkbox(field, ul_class='', **kwargs):
"""check wtforms.widgets.core to see what is going on"""
kwargs.setdefault('type', 'checkbox')
field_id = kwargs.pop('id', field.id)
html = [u'<ul %s>' % html_params(id=field_id, class_=ul_class)]
for value, label, checked in field.iter_choices():
choice_id = u'%s-%s' % (field_id, value)
options = dict(kwargs, name=field.name, value=value, id=choice_id)
if checked:
options['checked'] = 'checked'
html.append(u'<li><input %s /> ' % html_params(**options))
html.append(u'<label %s>%s</label></li>' % (html_params(**options), cgi.escape(text_type(label))))
else:
choice_id = u'%s-%s' %(field_id, u'other')
options = dict(kwargs, name=field.name, value='', id = choice_id)
options['type'] = 'text'
html.append(u'<input %s > ' % (html_params(**options)))
html.append(u'</ul>')
cPickle.dump(html, open("htmltest.p", "wb"))
return u''.join(html)
the part html.append(u'<input %s > ' % (html_params(**options))) is where textinput is added. (note that options['type'] = 'text' means type="text" attribute for <input> tag) The question is, How can I make hidden textinput (not type="hidden") so that I can reveal it via jquery later?
Add styling that hides it:
then use jQuery to show it: