KES777 / mojo

Mojolicious - Perl real-time web framework
http://mojolicio.us
Artistic License 2.0
0 stars 0 forks source link

Если есть optional поля, то они все должны быть заполнены #62

Open KES777 opened 5 years ago

KES777 commented 5 years ago
use Test::Mojo;
use Mojolicious::Lite;

get '/test' => 'form';

post '/test' => sub{
  my $self = shift;

  my $v =  $self->validation;

  $v->optional( 'cc_email' );

  my $cc =  $v->every_param( 'cc_email' );

  $self->render( text => join '--', @$cc );
} => 'post_form';

my $t = Test::Mojo->new;

my @emails =  ( 'test1@example.com', 'test2@example.com' );
$t->post_ok( '/test' => form => { cc_email => \@emails } )
  ->content_is( join '--', @emails );

@emails =  ('test1@example.com', ''); # When user fill only one form field
$t->post_ok( '/test' => form => { cc_email => \@emails } )
  ->content_is( 'test1@example.com' );

__DATA__

@@ form.html.ep
%= form_for 'post_form', begin
  <input name="cc_email">
  <input name="cc_email">
%= submit_button
% end

в этом примере мы не может заполнить только одно cc_email