Skip to content

Commit

Permalink
fixed select_field helper to be nondestructive
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 17, 2014
1 parent c3ae16e commit 9d8e446
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -11,6 +11,7 @@
- Improved Mojo::IOLoop::Server to use address and port for descriptor
inheritance.
- Improved list of available commands to be alphabetical. (jberger)
- Fixed select_field helper to be nondestructive.

4.67 2014-01-11
- Added history and max_history_size attributes to Mojo::Log.
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojolicious/Plugin/TagHelpers.pm
Expand Up @@ -167,9 +167,9 @@ sub _select_field {

# "optgroup" tag
if (blessed $group && $group->isa('Mojo::Collection')) {
my ($label, $values) = splice @$group, 0, 2;
my ($label, $values, %attrs) = @$group;
my $content = join '', map { _option(\%values, $_) } @$values;
$groups .= _tag('optgroup', label => $label, @$group, sub {$content});
$groups .= _tag('optgroup', label => $label, %attrs, sub {$content});
}

# "option" tag
Expand Down
13 changes: 13 additions & 0 deletions t/mojolicious/tag_helper_lite_app.t
Expand Up @@ -41,6 +41,19 @@ post '/no_snowman';

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

# Reuse values
my $values = [app->c(EU => [qw(de en)])];
is app->select_field(country => $values),
'<select name="country"><optgroup label="EU">'
. '<option value="de">de</option>'
. '<option value="en">en</option>'
. '</optgroup></select>', 'right result';
is app->select_field(country => $values),
'<select name="country"><optgroup label="EU">'
. '<option value="de">de</option>'
. '<option value="en">en</option>'
. '</optgroup></select>', 'right result';

# Basic tags
$t->options_ok('/tags')->status_is(200)->content_is(<<EOF);
<foo />
Expand Down

0 comments on commit 9d8e446

Please sign in to comment.