[Catalyst] Design of a new form validator
Sebastian Riedel
sri at oook.de
Thu Dec 1 09:28:10 CET 2005
Am 01.12.2005 um 07:35 schrieb Bill Moseley:
> On Thu, Dec 01, 2005 at 12:15:17AM +0100, Sebastian Riedel wrote:
>> Here's a mockup:
>>
>> use HTML::Widget;
>>
>> my $w = HTML::Widget->new( { method => 'POST, 'action => '/foo/
>> action' } );
>> $w->element( 'Textfield', 'age' )->label('Age')->size(3);
>> $w->element( 'Textfield', 'name' )->label('Name')->size(60);
>> $w->element( 'Submit', 'ok' )->value('OK');
>> $w->constraint( 'Integer', 'age' )->message('No integer.');
>> $w->constraint( 'Required', 'age', 'name' )->message('Missing
>> value.');
>
> So are you defining a text field "age" and then adding an Integer
> constraint to that field? Kind of like DFV, where you define a field
> and then add constraints on that field?
>
> Seems like there's only a handful of different types of fields. So,
> how about $w->element( 'AgeField', age ) which knows it should be in
> the range of 0 to 200 (with a bit of luck). And then add additional
> validation if needed when you need a specific range.
Hooks are already there. :)
>
>> [% form.as_xml %]
>
> Is that the entire form? I can't imagine that working in most cases
> -- forms always seem to need to be customized, so I find that I have
> to build the form field-by-field in the template.
I've just uploaded a new snapshot that has exactly this feature. :)
my @form = $f->element;
my $age = $f->element('age');
print $age->label_xml;
print $age->element_xml;
print $age->error_xml;
--
sebastian
More information about the Catalyst
mailing list