Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

HTML Widgets!

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


sri at oook

Dec 2, 2005, 9:21 AM

Post #1 of 7 (3604 views)
Permalink
HTML Widgets!

Some more HTML::Widget goodness, fresh from trunk... :)

http://dev.catalyst.perl.org/repos/Catalyst/trunk/HTML-Widget



use HTML::Widget;

# You can naturally use the validator without form generation!
my $w1 = HTML::Widget->new;
$w1->constraint( 'Integer', 'age' );
$w1->constraint( 'Alternative', 'age', 'name' );
my $form = $w1->process($query);
my @errors = $form->errors;


# Or only generate forms
my $w2 = HTML::Widget->new( { name => 'w2', action => '/foo' } );
$w2->element( 'Textfield', 'age' )->label('Age')->size(3);
$w2->element( 'Textfield', 'name' )->label('Name')->size(60);
my $form = $w2->process;
print "$form";


# Why not merge our widgets for both?
$w1->merge($w2);


# Now this is really cool, multiple embedded widgets (using
<fieldset>)
my $w3 = HTML::Widget->new( { name => 'w3' } );
$w3->element( 'Textarea', 'story' )->label('Story');
$w3->constraint( 'ASCII', 'story' );
my $container = HTML::Widget->new( { action => '/baz' } );
$w1->name('w1');
$container->embed( $w1, $w3 );
$form = $container->process($query);


The generated XML will look like this example: (easy to style with css)

<form action="/baz" id="widget" method="post">
<fieldset id="widget_w1">
<label for="widget_w1_age" id="widget_w1_age_label">Age</
label>
<input id="widget_widget_age" name="age" size="3"
type="textfield" />
<label for="widget_widget_name"
id="widget_widget_name_label">Name</label>
<input id="widget_widget_name" name="name" size="60"
type="textfield" />
</fieldset>
<fieldset id="widget_w3"><label for="widget_w3_story"
id="widget_w3_story_label">Story</label>
<textarea id="widget_w3_story" name="story"></textarea>
<span class="errors" id="widget_story_errors">
<span class="ASCII_errors"
id="widget_story_error_ASCII">Some useful Error message.</span>
</span>
</fieldset>
</form>


These are just very basic examples, you could also create element
classes with built-in constraints, js-validators or ajax... :)


--
sebastian


_______________________________________________
Catalyst mailing list
Catalyst [at] lists
http://lists.rawmode.org/mailman/listinfo/catalyst


sri at oook

Dec 2, 2005, 9:29 AM

Post #2 of 7 (3427 views)
Permalink
Re: HTML Widgets! [In reply to]

> <input id="widget_widget_age" name="age" size="3"
> type="textfield" />
> <label for="widget_widget_name"
> id="widget_widget_name_label">Name</label>
> <input id="widget_widget_name" name="name" size="60"
> type="textfield" />

Just a typo, that should be "widget_w1_*"...


--
sebastian


_______________________________________________
Catalyst mailing list
Catalyst [at] lists
http://lists.rawmode.org/mailman/listinfo/catalyst


info at whawes

Dec 2, 2005, 9:29 AM

Post #3 of 7 (3419 views)
Permalink
Re: HTML Widgets! [In reply to]

> Some more HTML::Widget goodness, fresh from trunk... :)
>
> http://dev.catalyst.perl.org/repos/Catalyst/trunk/HTML-Widget
>
>
>
> use HTML::Widget;
>
> # You can naturally use the validator without form generation!
> my $w1 = HTML::Widget->new;
> $w1->constraint( 'Integer', 'age' );
> $w1->constraint( 'Alternative', 'age', 'name' );
> my $form = $w1->process($query);
> my @errors = $form->errors;
>
>
> # Or only generate forms
> my $w2 = HTML::Widget->new( { name => 'w2', action => '/foo' } );
> $w2->element( 'Textfield', 'age' )->label('Age')->size(3);
> $w2->element( 'Textfield', 'name' )->label('Name')->size(60);
> my $form = $w2->process;
> print "$form";
>
>
> # Why not merge our widgets for both?
> $w1->merge($w2);
>
>
> # Now this is really cool, multiple embedded widgets (using
> <fieldset>)
> my $w3 = HTML::Widget->new( { name => 'w3' } );
> $w3->element( 'Textarea', 'story' )->label('Story');
> $w3->constraint( 'ASCII', 'story' );
> my $container = HTML::Widget->new( { action => '/baz' } );
> $w1->name('w1');
> $container->embed( $w1, $w3 );
> $form = $container->process($query);
>
>
> The generated XML will look like this example: (easy to style with css)
>
> <form action="/baz" id="widget" method="post">
> <fieldset id="widget_w1">
> <label for="widget_w1_age" id="widget_w1_age_label">Age</
> label>
> <input id="widget_widget_age" name="age" size="3"
> type="textfield" />
> <label for="widget_widget_name"
> id="widget_widget_name_label">Name</label>
> <input id="widget_widget_name" name="name" size="60"
> type="textfield" />
> </fieldset>
> <fieldset id="widget_w3"><label for="widget_w3_story"
> id="widget_w3_story_label">Story</label>
> <textarea id="widget_w3_story" name="story"></textarea>
> <span class="errors" id="widget_story_errors">
> <span class="ASCII_errors"
> id="widget_story_error_ASCII">Some useful Error message.</span>
> </span>
> </fieldset>
> </form>
>
>
> These are just very basic examples, you could also create element
> classes with built-in constraints, js-validators or ajax... :)
>
>
> --
> sebastian

It all looks good. Do you now prefer this approach over DBIx::Class::WebForm?


_______________________________________________
Catalyst mailing list
Catalyst [at] lists
http://lists.rawmode.org/mailman/listinfo/catalyst


sri at oook

Dec 2, 2005, 9:45 AM

Post #4 of 7 (3425 views)
Permalink
Re: HTML Widgets! [In reply to]

Am 02.12.2005 um 18:29 schrieb Will Hawes:
>
> It all looks good. Do you now prefer this approach over
> DBIx::Class::WebForm?
>

WebForm is just a very ugly hack. (like CDBI::AsForm and CDBI::FromForm)
I never actually used it. :)

We are working on something much better, H::W is just one Lego block.


--
sebastian


_______________________________________________
Catalyst mailing list
Catalyst [at] lists
http://lists.rawmode.org/mailman/listinfo/catalyst


johanl at DarSerMan

Dec 2, 2005, 11:39 AM

Post #5 of 7 (3443 views)
Permalink
Re: HTML Widgets! [In reply to]

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?


/J


_______________________________________________
Catalyst mailing list
Catalyst [at] lists
http://lists.rawmode.org/mailman/listinfo/catalyst


sri at oook

Dec 2, 2005, 12:34 PM

Post #6 of 7 (3407 views)
Permalink
Re: HTML Widgets! [In reply to]

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


_______________________________________________
Catalyst mailing list
Catalyst [at] lists
http://lists.rawmode.org/mailman/listinfo/catalyst


info at whawes

Dec 3, 2005, 6:33 AM

Post #7 of 7 (3414 views)
Permalink
Re: HTML Widgets! [In reply to]

>
> 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

It would be really good if all this could be loaded from an XML string, so
it could be stored within a model class, database, etc.


_______________________________________________
Catalyst mailing list
Catalyst [at] lists
http://lists.rawmode.org/mailman/listinfo/catalyst

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.