[Catalyst] HTML::FormHandler IDs not playing with JQuery

Victor Churchill victorchurchill at gmail.com
Tue Mar 29 10:43:40 GMT 2011

In my questionnaire.pm:

# question 1 #
# If you do like a drink we will pop up the subquestions

my @opts= map {value=>$_,label=>$_},
  ('Yep','No Never','Now and Then');

has_field 'Q1' => (
                   label => "Yo dude, do you like a drink?",
                   type => 'Select', widget => 'radio_group',
                   options => \@opts,
                   id => 'q1_select',
                   title => 'if you say yes, we will ask you more...',
                   css_class => 'question parentquestion',
                   required => 1 );

has_field 'Q1_0' => ( label=>'Hang on, how old are you?', type=>'Integer',
                      range_start=>6, range_end=>99,
                      css_class => 'question childquestion',
                      id => 'q1_age',

This renders to

<div class="question parentquestion">
<label class="label" for="q1_select">Yo dude, do you like a drink?:
</label> <br />
<label for="q1_select.0"><input type="radio" value="Yep" name="Q1"
id="q1_select.0" />Yep</label><br />
<label for="q1_select.1"><input type="radio" value="No Never"
name="Q1" id="q1_select.1" />No Never</label><br />
<label for="q1_select.2"><input type="radio" value="Now and Then"
name="Q1" id="q1_select.2" />Now and Then</label><br /></div>

<div class="question childquestion">
<label class="label" for="q1_age">Hang on, how old are you?: </label>
<input type="text" name="Q1_0" id="q1_age" size="8" value="" /></div>

Trouble is I would like to use id="q1_select.0" as a JQuery selector
to control the show/hide of 'child' questions, and the selector does
not like the ".0". I determined with a couple of manual tests that I
can't select an item with a period in the ID - or so it appears

Is there a way round this? I would have thought that if I am missing
something , I might not be the first.

(Oh, and by the way: can anyone point me at a "better/best practice"
way to specify the 'options' for a HFH select field?)

best regards,

Victor Churchill,

More information about the Catalyst mailing list