Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
improved text_field helper to always set the type attribute
  • Loading branch information
kraih committed Jul 19, 2012
1 parent a228918 commit d6b06fa
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,5 +1,6 @@

3.12 2012-07-20
- Improved text_field helper to always set the type attribute. (marty, sri)
- Improved documentation.

3.11 2012-07-19
Expand Down
2 changes: 2 additions & 0 deletions lib/Mojolicious.pm
Expand Up @@ -837,6 +837,8 @@ Maik Fischer
Mark Stosberg
Marty Tennison
Matthew Lineen
Maksym Komar
Expand Down
16 changes: 8 additions & 8 deletions lib/Mojolicious/Plugin/TagHelpers.pm
Expand Up @@ -23,7 +23,7 @@ sub register {

# Add "file_field" helper
$app->helper(file_field =>
sub { shift; $self->_tag('input', name => shift, type => 'file', @_) });
sub { shift; $self->_tag('input', name => shift, @_, type => 'file') });

# Add "form_for" helper
$app->helper(
Expand All @@ -50,7 +50,7 @@ sub register {
$app->helper(
hidden_field => sub {
shift;
my %attrs = (type => 'hidden', name => shift, value => shift, @_);
my %attrs = (name => shift, value => shift, @_, type => 'hidden');
return $self->_tag('input', %attrs);
}
);
Expand Down Expand Up @@ -107,7 +107,7 @@ sub register {
$app->helper(
password_field => sub {
shift;
$self->_tag('input', name => shift, type => 'password', @_);
$self->_tag('input', name => shift, @_, type => 'password');
}
);

Expand Down Expand Up @@ -192,7 +192,7 @@ sub register {
$app->helper(
submit_button => sub {
shift;
$self->_tag('input', value => shift // 'Ok', type => 'submit', @_);
$self->_tag('input', value => shift // 'Ok', @_, type => 'submit');
}
);

Expand Down Expand Up @@ -221,7 +221,7 @@ sub register {
);

# Add "text_field" helper
$app->helper(text_field => sub { $self->_input(@_) });
$app->helper(text_field => sub { $self->_input(@_, type => 'text') });
}

sub _input {
Expand Down Expand Up @@ -574,9 +574,9 @@ accidental double escaping.
Generate text input element. Previous input values will automatically get
picked up and shown as default.
<input name="first_name" />
<input name="first_name" value="Default name" />
<input class="user" name="first_name" value="Default name" />
<input name="first_name" type="text" />
<input name="first_name" type="text" value="Default name" />
<input class="user" name="first_name" type="text" value="Default name" />
=head2 C<text_area>
Expand Down
10 changes: 5 additions & 5 deletions t/mojolicious/tag_helper_lite_app.t
Expand Up @@ -128,9 +128,9 @@ EOF
# GET /basicform
$t->get_ok('/basicform')->status_is(200)->content_is(<<EOF);
<form action="/links">
<input name="foo" value="bar" />
<input class="test" name="bar" value="baz" />
<input name="yada" value="" />
<input name="foo" type="text" value="bar" />
<input class="test" name="bar" type="text" value="baz" />
<input name="yada" type="text" value="" />
<input class="tset" name="baz" value="yada" />
<input type="submit" value="Ok" />
</form>
Expand Down Expand Up @@ -188,7 +188,7 @@ $t->get_ok('/form/lala?a=2&b=0&c=2&d=3&escaped=1%22+%222')->status_is(200)
<input name="foo" />
</form>
<form action="/form/24" method="post">
<input name="foo" />
<input name="foo" type="text" />
<input name="foo" type="checkbox" value="1" />
<input checked="checked" name="a" type="checkbox" value="2" />
<input name="b" type="radio" value="1" />
Expand Down Expand Up @@ -218,7 +218,7 @@ $t->get_ok('/form/lala?c=b&d=3&e=4&f=<5')->status_is(200)->content_is(<<EOF);
<input name="foo" />
</form>
<form action="/form/24" method="post">
<input name="foo" />
<input name="foo" type="text" />
<input name="foo" type="checkbox" value="1" />
<input name="a" type="checkbox" value="2" />
<input name="b" type="radio" value="1" />
Expand Down

0 comments on commit d6b06fa

Please sign in to comment.