FAQ
Apologies if this not the right forum for this (but if not, where else
?). According to the FormBuilder docs, the following code in my template
should (and does) work:

[% FOREACH field IN form.fields %]
<td>[% field.label %]</td>
<td>[% field.field%]</td>
[% END %]

But so should this (and doesn't):
<td>[% form.field.location.label %]</td>
<td>[% form.field.location.field%]</td>

'location' is a valid field_name. Dumper.dump(form.field.location) is
empty (as is every other form.field.legal_field_name).

According to the FormBuilder docs that is how to access individual
fields if requiring finer control in the template than is provided by
FormBuilder.render (which also works by the way).

So what am I doing wrong? Thanks.
--
Richard Jones
Leeds, UK

**********************************************************************
This message may contain confidential and privileged information.
If you are not the intended recipient please accept our apologies.
Please do not disclose, copy or distribute information in this e-mail
or take any action in reliance on its contents: to do so is strictly
prohibited and may be unlawful. Please inform us that this message has
gone astray before deleting it. Thank you for your co-operation.

NHSmail is used daily by over 100,000 staff in the NHS. Over a million
messages are sent every day by the system. To find out why more and
more NHS personnel are switching to this NHS Connecting for Health
system please visit www.connectingforhealth.nhs.uk/nhsmail
**********************************************************************

Search Discussions

  • Peter Edwards at Apr 27, 2007 at 2:22 pm
    If fields is a list reference you need something like

    [% form.fields.0.label %]

    http://www.template-toolkit.org/docs/aqua/Manual/Variables.html#Hash_Array_R
    eferences

    Regards, Peter
    Dragonstaff Limited http://www.dragonstaff.com

    -----Original Message-----
    From: RA Jones
    Sent: 27 April 2007 13:47
    To: catalyst@lists.rawmode.org
    Subject: [Catalyst] CC::FormBuilder woes

    Apologies if this not the right forum for this (but if not, where else
    ?). According to the FormBuilder docs, the following code in my template
    should (and does) work:

    [% FOREACH field IN form.fields %]
    <td>[% field.label %]</td>
    <td>[% field.field%]</td>
    [% END %]

    But so should this (and doesn't):
    <td>[% form.field.location.label %]</td>
    <td>[% form.field.location.field%]</td>
  • Richard Jones at Apr 27, 2007 at 4:40 pm

    Peter Edwards wrote:
    If fields is a list reference you need something like

    [% form.fields.0.label %]

    http://www.template-toolkit.org/docs/aqua/Manual/Variables.html#Hash_Array_R
    eferences
    Oh dear, that works! But it's not what I want as I can't easily force
    specific fields where I want them spatially if I have to loop over an
    array. I want some table rows to contain 3 fields, and others to contain
    one or two. I can do this if manipulating a hash(ref), but with an
    array(ref) it is very messy.

    The CGI::FormBuilder::Template::TT2 documentation distinctly gives the
    impression I can retrieve fields from the form.field hash:

    You can access individual fields via the |field| variable.

    For a field named... The field data is in...
    -------------------- -----------------------
    job [% form.field.job %]
    size [% form.field.size %]
    email [% form.field.email %]


    Then use eg form.field.location.label in the template. I have done this
    previously using CGI::FormBuilder in a stand-alone environment, so I
    must be missing something obvious here.
    --
    Richard Jones
    Leeds, UK

    **********************************************************************
    This message may contain confidential and privileged information.
    If you are not the intended recipient please accept our apologies.
    Please do not disclose, copy or distribute information in this e-mail
    or take any action in reliance on its contents: to do so is strictly
    prohibited and may be unlawful. Please inform us that this message has
    gone astray before deleting it. Thank you for your co-operation.

    NHSmail is used daily by over 100,000 staff in the NHS. Over a million
    messages are sent every day by the system. To find out why more and
    more NHS personnel are switching to this NHS Connecting for Health
    system please visit www.connectingforhealth.nhs.uk/nhsmail
    **********************************************************************
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070427/67281245/attachment.htm
  • Juan Camacho at Apr 27, 2007 at 11:35 pm

    On 4/27/07, RA Jones wrote:
    Peter Edwards wrote:
    If fields is a list reference you need something like

    [% form.fields.0.label %]

    http://www.template-toolkit.org/docs/aqua/Manual/Variables.html#Hash_Array_R
    eferences


    Oh dear, that works! But it's not what I want as I can't easily force
    specific fields where I want them spatially if I have to loop over an array.
    I want some table rows to contain 3 fields, and others to contain one or
    two. I can do this if manipulating a hash(ref), but with an array(ref) it is
    very messy.

    The CGI::FormBuilder::Template::TT2 documentation distinctly gives the
    impression I can retrieve fields from the form.field hash:

    You can access individual fields via the field variable. For a field
    named... The field data is in...
    -------------------- -----------------------
    job [% form.field.job %]
    size [% form.field.size %]
    email [% form.field.email %]


    Then use eg form.field.location.label in the template. I have done this
    previously using CGI::FormBuilder in a stand-alone environment, so I must be
    missing something obvious here.

    Hmm, that is odd. There is actually a unit test that is included to
    test that specific functionality out.

    http://search.cpan.org/src/JCAMACHO/Catalyst-Controller-FormBuilder-0.03/t/root/src/tt2/books/basic.tt

    Maybe there is an unexpected stash issue. Try to create a minimalist
    example (with form, template and controller code) and post here.
  • Richard Jones at Apr 28, 2007 at 8:53 am

    Juan Camacho wrote:
    On 4/27/07, RA Jones wrote:
    The CGI::FormBuilder::Template::TT2 documentation distinctly gives the
    impression I can retrieve fields from the form.field hash:

    You can access individual fields via the field variable. For a field
    named... The field data is in...
    -------------------- -----------------------
    job [% form.field.job %]
    size [% form.field.size %]
    email [% form.field.email %]


    Then use eg form.field.location.label in the template. I have done this
    previously using CGI::FormBuilder in a stand-alone environment, so I
    must be
    missing something obvious here.

    Hmm, that is odd. There is actually a unit test that is included to
    test that specific functionality out.

    http://search.cpan.org/src/JCAMACHO/Catalyst-Controller-FormBuilder-0.03/t/root/src/tt2/books/basic.tt


    Maybe there is an unexpected stash issue. Try to create a minimalist
    example (with form, template and controller code) and post here.
    OK, will do. But would it be easier if I posted the output of
    Dumper.dump(form)? Also just realised I'm using CCF 0.02 - could that
    affect it (can't update it at the moment). Changes file doesn't suggest
    it would.
    --
    Richard Jones
    Leeds, UK
  • Juan Camacho at Apr 28, 2007 at 1:01 pm

    On 4/28/07, Richard Jones wrote:
    Juan Camacho wrote:
    Maybe there is an unexpected stash issue. Try to create a minimalist
    example (with form, template and controller code) and post here.
    OK, will do. But would it be easier if I posted the output of
    Dumper.dump(form)? Also just realised I'm using CCF 0.02 - could that
    affect it (can't update it at the moment). Changes file doesn't suggest
    it would.
    --
    No, 0.03 shouldn't make much a difference, but at least on your
    development server, I would suggest using it locally. In fact, the
    quickest option is to just modify the test files under t/lib and
    t/root to come up with some scenario that breaks the 'perl -Mblib
    t/01-basic.t' test.
  • Richard Jones at Apr 30, 2007 at 6:34 pm

    Juan Camacho wrote:
    On 4/28/07, Richard Jones wrote:
    Juan Camacho wrote:
    Maybe there is an unexpected stash issue. Try to create a minimalist
    example (with form, template and controller code) and post here.
    OK, will do. But would it be easier if I posted the output of
    Dumper.dump(form)? Also just realised I'm using CCF 0.02 - could that
    affect it (can't update it at the moment). Changes file doesn't suggest
    it would.
    --
    No, 0.03 shouldn't make much a difference, but at least on your
    development server, I would suggest using it locally. In fact, the
    quickest option is to just modify the test files under t/lib and
    t/root to come up with some scenario that breaks the 'perl -Mblib
    t/01-basic.t' test.
    Actually, it _was_ a stash issue, but all down to my misuse of it! Once
    I used the correct term for it (default = formbuilder), or over-rode it
    with the Controller::FormBuilder config entry stash_name =>
    something_else, it worked fine. Thanks for the pointer.
    --
    Richard Jones
    Leeds, UK

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedApr 27, '07 at 1:45p
activeApr 30, '07 at 6:34p
posts7
users3
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2022 Grokbase