-
-
Save ssoriche/3a1e5549e1c7f80dcdfa to your computer and use it in GitHub Desktop.
Mojolicious::Plugin::TagHelpers check_box checked from stash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub _input { | |
my ($self, $c, $name) = (shift, shift, shift); | |
say "Attributes: " . p @_; | |
# Odd | |
my %attrs; | |
if (@_ % 2) { | |
my $value = shift; | |
%attrs = (@_, value => $value); | |
} | |
# Even | |
else { %attrs = @_ } | |
say "Attributes: " . p %attrs; | |
# Value | |
my @p = $c->param($name) || $c->stash($name); # <---- Change here | |
# my @p = $c->param($name); | |
say "Name: $name Parameters: " . p @p; | |
# Special selection value | |
my $t = $attrs{type} || ''; | |
if (@p && $t ne 'submit') { | |
# Checkbox or radiobutton | |
my $value = $attrs{value} // ''; | |
if ($t eq 'checkbox' || $t eq 'radio') { | |
say("Value: *$value*"); | |
$attrs{value} = $value; | |
$attrs{checked} = 'checked' if defined first { $value eq $_ } @p; | |
} | |
# Other | |
else { $attrs{value} = $p[0] } | |
return $self->_tag('input', name => $name, %attrs); | |
} | |
# Empty tag | |
say("Name: $name"); | |
return $self->_tag('input', name => $name, %attrs); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe this can help: https://github.com/sshaw/Mojolicious-Plugin-FormFields