[Catalyst] HTML::Widget and optional form fields (with checks)
Michele Beltrame
mb at italpro.net
Wed Mar 29 23:50:44 CEST 2006
Hello!
I have a small problem in defining optional fields with checks (if not
empty) with HTML::Widget.
I have a form similar to thee one you can see at the end of this
message. I use strict(1) and the Maybe constraint because I want to cut
out from the "valid list" some fields which have nothing to do with the
data of the form itself (I use them for redirecting and such). With the
Maybe constraint and strict(1) I ensure that only the fields I define
here, no matter if they're empty or not, go into the "valid list".
However, I have a need which I don't know how to fullfill. I'd like the
"birthdate" field to be considered valid if it matches the Regex shown
below OR if it's empty; that is, it doesn't have to be considered valid
if it's not empty, unless it matches the Regex.
Is there a way to accomplish this? The code I've come up with requires
the "birthdate" field to match the regex anyway.
my $w = $c->widget('emodify');
[...]
$w->indicator('idrole');
$w->strict(1);
$w->element('Textfield', 'username');
$w->element('Textfield', 'birthdate');
$w->constraint('All', qw/username/);
$w->constraint('Maybe', qw/birthdate/);
$w->constraint('Regex', qw/birthdate/)->regex(
qr/\A \d{4}-\d{2}-\d{2} \z/xms
);
Thanks in advance,
Michele.
--
Michele Beltrame
http://www.varlogarthas.net/
ICQ# 76660101
Informativa privacy: http://www.italpro.net/em.html
More information about the Catalyst
mailing list