[Html-widget] Composed widgets
Michael Gray
mjg17 at eng.cam.ac.uk
Tue Oct 10 13:55:22 CEST 2006
On Mon, 9 Oct 2006, Zbigniew Lukasiak wrote:
> I wanted to write a simple HTML::Widget::Element that would generate a
> Password field together with a confirmation. It is easy to just use
> two Password elements - but I wanted to simplify creating standard
> forms a bit more and have an
> HTML::Widget::Element::PasswordWithConfirmation element together with
> a custom HTML::Widget::Constraint. Of course I can write it from
> scratch - but wouldn't it be nice if you could compose several
> HTML::Widget::Element's into one complex? Is there a simple way to do
> that? This technique could be used also for date and time - where one
> conceptual input needs to be broken in the form into several fields.
There is a somewhat outdated start on this at:
http://dev.catalystframework.org/browser/trunk/HTML-Widget-Canned
I haven't looked at this recently to see how it fits with the current
structure of HTML::Widget.
I have my own lump of password validation stuff, some of which was
nicked from H::W::Canned:
------------------------------------------------------------------------
$fs->element( Password => $id )
->label($label)->size($max_length);
$fs->element( Password => "${id}_retype" )
->label("Retype $label")->size($max_length);
$widget->constraint( All => $id )
->message("You must choose a password.");
$widget->constraint( All => "${id}_retype" )
->message("You must retype the password.");
$widget->constraint( Equal => ($id, "${id}_retype") )
->message("The passwords don't match.");
$widget->constraint( Length => $id )->min( $min_length )
->message(
"The password must contain at least $min_length characters."
);
$widget->constraint( Length => $id )->max( $max_length )
->message(
"The password must contain no more than $max_length characters."
);
# Quality checks here
#
$widget->constraint( Regex => $id )
->regex(qr/[~\`!\$\%^&*()_\-+=\{\}\[\]|:;\'\"<>,.\/?]/)
->message(
'The password must contain at least one punctuation character' .
' from ~`!$%^&*()_-+={}[]|:;\'\"<>,./?'
);
$widget->constraint( Not_Regex => $id )
->regex(qr/[\\\#@]/)
->message(
'The password must not contain the following characters: \ @ #'
);
$widget->constraint( Not_Regex => $id )
->regex(qr/747!ada%/)
->message('Please do not use the example password')
------------------------------------------------------------------------
--
Michael
More information about the Html-widget
mailing list