[Catalyst] HTML Widgets!

Sebastian Riedel sri at oook.de
Fri Dec 2 21:34:32 CET 2005


Am 02.12.2005 um 20:39 schrieb Johan Lindström:

> At 18:21 2005-12-02, Sebastian Riedel wrote:
>>    $w2->element( 'Textfield', 'age' )->label('Age')->size(3);
>>     $w2->element( 'Textfield', 'name' )->label('Name')->size(60);
>
> The size spec, is that used for validation also?
>
> If there is a size/length constraint for e.g. name, is it used as  
> the default size in the element?

Not for the default elements.

But subclassing them to create new ones is very easy. ;)


     package HTML::Widget::Element::Textfield_C;
     use base 'HTML::Widget::Element::Textfield';

     sub init {
         my ( $self, $w ) = @_;
         $w->constraint( 'Length', $self->name )->max($self->size) if  
$self->size;
     }

     1;


Thats it!

     $widget->element( 'Textfield_C', 'foo' );


I'm sure we'll see lots of new elements soon, so we better get a  
naming convention.

H::W::E::Foo_J  - Element/Constraint with integrated JS
H::W::C::Foo_J
H::W::E::Foo_JX - Element/Constraint with JS and external dependency  
(prototype.js...)
H::W::C::Foo_JX
H::W::E::Foo_C   - Element with Constraints
H::W::C::Foo_E   - Constraint with Element



--
sebastian




More information about the Catalyst mailing list