[Catalyst] automatic form generation based on data models

Josef Karthauser joe at tao.org.uk
Wed Nov 8 21:41:56 GMT 2006


On Wed, Nov 08, 2006 at 12:13:53PM -0800, Bill Moseley wrote:
> Well, in my case currently this is all I'd need to do:
> 
>     [% # Template to generate a standard form
> 
>         WRAPPER form_wrapper;
>             FOR f = form.fields;
>                 field(form, f );
>             END;
>         END;
> 
>     %]

Hi Bill,

Which module are you using to get this syntax?

I've started using HTML::Widget, building the edit boxes within the
controller, and then formatting them in the template:

    [%- SET count = 0 -%]
    <table id="matrix">
      [%- FOREACH column IN fields; -%]
      [% "<tr";
	 ' class="alternate"' IF count % 2;
	 ">" %]
	<th> [% headings.$count %] </th>
	<td>
	     [% edit = widget.get_element('name', column) %]
	     [% IF edit %]
		[% foo=edit.value(record.$column);
		   edit.field_xml;
		   widget.result.element(column) %]
	     [% ELSE %]
		[% perhaps_link(record, fieldtable, column) %]
	     [% END %]
	</td>
      </tr>
      [%- SET count = count + 1 -%]
      [% END %]
    </table>

The real mess comes though with views which contain data from other
tables, i.e. $record->owner->username for instance, which in the
template would look like record.owner.username.  This is a bit of pain
actually, because there is no such column as "owner.username", i.e. I
can't do

	[% field = "owner.username"; record.field %]

This means I have to be very careful with column names, both in
the record, and in the widget.

It's not as clean as I'd like :/.

Joe
-- 
Josef Karthauser (joe at tao.org.uk)	       http://www.josef-k.net/
Physics Particle Theory (student)   http://www.pact.cpes.sussex.ac.uk/
================ An eclectic mix of fact and theory. =================
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
Url : http://jules.scsys.co.uk/pipermail/catalyst/attachments/20061108/96ee189c/attachment.pgp


More information about the Catalyst mailing list