SV: [Catalyst] Problem with TT view and form.field

Peter Sørensen maspsr at sdu.dk
Fri Jan 18 07:05:37 GMT 2008


Hi Jason,

Thanks for looking into the problem. I have tried your
suggested syntax but still no output.

I can access the information with:

	form.field.3.label

where 3 is the index in the array but this is not what I want.
I want to be able to address the content using the name of the field.

regards

Peter
				
		
-----Oprindelig meddelelse-----
Fra: Jason Kohles [mailto:email at jasonkohles.com] 
Sendt: 17. januar 2008 15:49
Til: The elegant MVC web framework
Emne: Re: [Catalyst] Problem with TT view and form.field

On Jan 17, 2008, at 2:39 AM, Peter Sørensen wrote:

I don't know much about FormBuilder, however...

> The output is OK but as I understood the docs it should also be 
> possible to access this directly.
>
> [% fields %]  -  List of fields
> [% field  %]  -  Hash of fields (for lookup by name)

These are actually exactly the same method in CGI::FormBuilder, which
says:

*param  = \&field;
*params = \&field;
*fields = \&field;
sub field {

>
> Lets say I have a field named
> firstname then it should be possible to do:
>
> [% form.fields.firstname.label %]


The source for CGI::FormBuilder says that field, if called without an argument, will return "an array of the names in list context, and a hashref of name/value pairs in a scalar context".  This is problematic behavior with TT, as TT always uses a list context, so form.fields and form.field are both going to return an array of field names.

Looking at the source though, it looks like you should be able to get at them this way:

[% form.field( 'firstname' ).label %]

--
Jason Kohles, RHCA RHCDS RHCE
email at jasonkohles.com - http://www.jasonkohles.com/ "A witty saying proves nothing."  -- Voltaire



_______________________________________________
List: Catalyst at lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/



More information about the Catalyst mailing list