kevin montuori | 9 Feb 2007 23:56
Picon
Gravatar

[FormBuilder] validate + commas in FB source files


hi all -- first off, CGI::FB is a great module.  it's saved me
countless hours of tedious mind-numbing typing.  thanks a lot to
nate and anyone else responsible.

i have a question about using CGI::FormBuilder::Source::File with
regexps in the validate field: one of the things i really want to do
is make sure the length of the input is between a min and max value:

  validate: /^\w{3,32}$/

and it seems like this sort of thing would be not atypical.
unfortunately, the regex is split into two values when there's a comma
in the regex (via $source->write_module()):

  'validate' => [
                  '/^\\w{3',
                  '32}$/'

so : is there a canonical way of checking for min/max length that i'm
not aware of?  

would there be any interest in changing File.pm (~ line 155) from:

   # split commas
    <at> val = split /\s*,\s*/, $line;

to something like:

   # split commas
(Continue reading)

Alexandre Jousset | 13 Mar 2007 12:33
Favicon
Gravatar

Re: [FormBuilder] validate + commas in FB source files

	Hello list,

kevin montuori wrote:
> hi all -- first off, CGI::FB is a great module.  it's saved me
> countless hours of tedious mind-numbing typing.  thanks a lot to
> nate and anyone else responsible.

	Same for me. I'm new to it and find it very useful.

> i have a question about using CGI::FormBuilder::Source::File with
> regexps in the validate field: one of the things i really want to do
> is make sure the length of the input is between a min and max value:
> 
>   validate: /^\w{3,32}$/

	I've had the same problem.

 > [...]
> to something like:
> 
>    # split commas
>    my $split_regex = lc $term eq 'validate'
>      ? qr/\s*(?<!\\),\s*/ : qr/\s*,\s*/;
>     <at> val = split $split_regex, $line;
> 
> which would allow this statement in the source file:
> 
>    validate: /^\w{3\,32}$/
> 
> to produce the more useful:
(Continue reading)

Nate Wiger | 13 Mar 2007 16:21
Picon
Gravatar

Re: [FormBuilder] validate + commas in FB source files

Looks like a good addition.

>         I hope not to be too confusing, I can provide a real patch if needed (I
> am lazy today ;-) )

Please do. Provide a diff -u and also a couple tests, and I'll apply
it to the tree.

Thanks,
Nate
_______________________________________________
FBusers mailing list
FBusers <at> formbuilder.org
http://www.formbuilder.org/mailman/listinfo/fbusers

Alexandre Jousset | 14 Mar 2007 09:31
Favicon
Gravatar

Re: [FormBuilder] validate + commas in FB source files

	Hello Nate,

Nate Wiger wrote:
> Looks like a good addition.
> 
>>         I hope not to be too confusing, I can provide a real patch if 
>> needed (I
>> am lazy today ;-) )
> 
> Please do. Provide a diff -u and also a couple tests, and I'll apply
> it to the tree.

	Ok, here it is, in attachment.

	With it, I can use this kind of YAML config file (I use Catalyst):

	File '.../MyApp/root/forms/user/create.fb':

-----------------------------------------------------------
name: user_create
method: post
fields:
	login:
		label:    Login
		type:     text
		size:     40
		validate: /^.{4\,40}$/, /^\w*$/
		required: 1
		message:  Between 4 and 40 characters, Only alphanumeric characters
	disp_name:
(Continue reading)

Alexandre Jousset | 14 Mar 2007 09:37
Favicon
Gravatar

Re: [FormBuilder] validate + commas in FB source files

	Just a note :

Alexandre Jousset wrote:
> --- /root/.cpan/build/CGI-FormBuilder-3.0501/lib/CGI/FormBuilder/Field.pm       2007-03-02
19:13:14.000000000 +0100
> +++ /usr/local/share/perl/5.8.8/CGI/FormBuilder/Field.pm        2007-03-13 12:31:21.000000000 +0100
>  <at>  <at>  -620,7 +620,7  <at>  <at> 
>      elsif (ref $pattern eq 'ARRAY') {
>          # Must be w/i this set of values
>          # Can you figure out how this piece of Perl works? No, seriously, I forgot.
> -        $jsfunc .= qq[${in}if ($notnull ($jsfield != ']
> +        $jsfunc .= qq[${in}if ($notnull ($jsfield != \']
>                   . join("' && $jsfield != '",  <at> {$pattern}) . "')) {\n";

	This part of the patch is just for Emacs to be happy with syntax 
highlighting... Not really necessary...

	Regards,
--

-- 
--      \^/                                            --
--    -/ O \---------------------------------------    --
--   | |/ \|      Alexandre (Midnite) Jousset      |   --
--    -|___|---------------------------------------    --
_______________________________________________
FBusers mailing list
FBusers <at> formbuilder.org
http://www.formbuilder.org/mailman/listinfo/fbusers

Nate Wiger | 11 Feb 2007 21:20
Picon
Gravatar

Re: [FormBuilder] validate + commas in FB source files

On 2/9/07, kevin montuori <montuori <at> gmail.com> wrote:
> would there be any interest in changing File.pm (~ line 155) from:
>
>    # split commas
>     <at> val = split /\s*,\s*/, $line;
>
> to something like:
>
>    # split commas
>    my $split_regex = lc $term eq 'validate'
>      ? qr/\s*(?<!\\),\s*/ : qr/\s*,\s*/;
>     <at> val = split $split_regex, $line;

Sounds like a reasonable addition. I believe there was also some talk
on the list a short while ago about something similar for the js*
options. Can you check whether the same option would work to maintain
jsfunc et al intact?

-Nate
_______________________________________________
FBusers mailing list
FBusers <at> formbuilder.org
http://www.formbuilder.org/mailman/listinfo/fbusers


Gmane