| 1 | package Valiant::HTML::FormBuilder; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Module::Runtime (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Valiant::I18N; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | with 'Valiant::Naming'; | |||||||||||||||||||||||||||||||||||||||||
| 9 | # Non public helper methods | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 313 | ▶ | sub set_unless_defined { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_unless_defined: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 313 | my ($key, $options, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 13 | 313 | ▶ | return if exists($options->{$key}) && defined($options->{$key}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $options->{$key} and defined $options->{$key}
MC/DC50%1/2
exists $options->{$key} and defined $options->{$key}
exists $options->{$key}
defined $options->{$key}
Truth table66%2/3
A and B
A= exists $options->{$key}B= defined $options->{$key}
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 220 | $options->{$key} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | has model => ( is => 'ro', required => 1); | |||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | has name => ( is => 'ro', required => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | has options => ( is => 'ro', required => 1, default => sub { +{} } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | has index => ( is => 'ro', required => 0, predicate => 'has_index' ); | |||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | has namespace => ( is => 'ro', required => 0, predicate => 'has_namespace' ); | |||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | has tag_helpers => ( | |||||||||||||||||||||||||||||||||||||||||
| 23 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 24 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 25 | handles => [qw/view/], | ||||||||||||||||||||||||||||||||||||||||||
| 26 | builder => '_build_tag_helpers', | ||||||||||||||||||||||||||||||||||||||||||
| 27 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | ▶ | sub _build_tag_helpers { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_tag_helpers: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | my %args = (); | |||||||||||||||||||||||||||||||||||||||||
| 33 | $args{view} = exists($self->options->{view}) ? | ||||||||||||||||||||||||||||||||||||||||||
| 34 | $self->options->{view} : | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | ▶ | Module::Runtime::use_module('Valiant::HTML::Util::View')->new; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | return Module::Runtime::use_module('Valiant::HTML::Util::Form')->new(%args); | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 2 | has theme => ( is => 'ro', required => 1, lazy =>1, builder => '_build_theme' ); | |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 18 | ▶ | sub _build_theme { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_theme: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 18 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 18 | ▶ | my $theme = $self->can('default_theme') ? $self->default_theme : +{}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 18 | ▶ | my $view_theme = $self->view->can('formbuilder_theme') ? $self->view->formbuilder_theme : +{}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 18 | return +{ %$theme, %$view_theme }; | |||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 59 | ▶ | has _nested_child_index => (is=>'rw', init_arg=>undef, required=>1, default=>sub { +{} }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 59 | ▶ | around BUILDARGS => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.3
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 59 | my ($orig, $class, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 59 | my $options = $class->$orig(@args); | |||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 59 | ▶ | $options->{index} = $options->{child_index} if !exists($options->{index}) && exists($options->{child_index}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not exists $options->{"index"} and exists $options->{"child_index"}
MC/DC0%0/2
not exists $options->{"index"} and exists $options->{"child_index"}
not exists $options->{"index"}
exists $options->{"child_index"}
Truth table33%1/3
not(A) and B
A= not exists $options->{"index"}B= exists $options->{"child_index"}
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 59 | ▶ | $options->{options} = exists($options->{options}) ? +{%$options, %{$options->{options}}} : $options; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 59 | return $options; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub form_action { shift->options->{html}{action} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
form_action: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | ▶ | sub form_method { shift->options->{html}{method} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
form_method: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | ▶ | sub form_enctype { shift->options->{html}{enctype} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
form_enctype: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | sub csrf_token { shift->options->{html}{data}{csrf_token} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
csrf_token: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub containing_view { shift->options->{view} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
containing_view: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 189 | ▶ | sub allow_method_names_outside_object { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
allow_method_names_outside_object: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 189 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 68 | return exists($self->options->{allow_method_names_outside_object}) | ||||||||||||||||||||||||||||||||||||||||||
| 69 | ? $self->options->{allow_method_names_outside_object} | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 189 | ▶ | : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | sub DEFAULT_MODEL_ERROR_MSG_ON_FIELD_ERRORS { return 'Your form has errors' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DEFAULT_MODEL_ERROR_MSG_ON_FIELD_ERRORS: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub DEFAULT_MODEL_ERROR_TAG_ON_FIELD_ERRORS { return 'invalid_form' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DEFAULT_MODEL_ERROR_TAG_ON_FIELD_ERRORS: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 5 | ▶ | sub DEFAULT_COLLECTION_CHECKBOX_BUILDER { return 'Valiant::HTML::FormBuilder::Checkbox' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DEFAULT_COLLECTION_CHECKBOX_BUILDER: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 3 | ▶ | sub DEFAULT_COLLECTION_RADIO_BUTTON_BUILDER { return 'Valiant::HTML::FormBuilder::RadioButton' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DEFAULT_COLLECTION_RADIO_BUTTON_BUILDER: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | sub id { return shift->options->{id} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
id: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 4 | ▶ | sub nested_child_index { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nested_child_index: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 4 | my ($self, $attribute) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 4 | ▶ | if(exists($self->_nested_child_index->{$attribute})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 3 | return ++$self->_nested_child_index->{$attribute}; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | return $self->_nested_child_index->{$attribute} = 0 | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 228 | ▶ | sub tag_id_for_attribute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tag_id_for_attribute: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 228 | my ($self, $attribute, @extra) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 228 | my $opts = +{}; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 228 | ▶ | $opts->{namespace} = $self->namespace if $self->has_namespace; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 228 | ▶ | $opts->{index} = $self->index if $self->has_index; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 228 | return $self->tag_helpers->field_id($self->name, $attribute, $opts, @extra); | |||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | # $self->tag_name_for_attribute($attribute, +{ multiple=>1 }); | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 125 | ▶ | sub tag_name_for_attribute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tag_name_for_attribute: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 125 | my ($self, $attribute, $opts, @extra) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 125 | ▶ | $opts = +{} unless defined $opts; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 125 | ▶ | $opts->{namespace} = $self->namespace if $self->has_namespace; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 125 | ▶ | $opts->{index} = $self->index if $self->has_index; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 125 | return $self->tag_helpers->field_name($self->name, $attribute, $opts, @extra); | |||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 189 | ▶ | sub tag_value_for_attribute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tag_value_for_attribute: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 189 | my ($self, $attribute, $options) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 110 | my %options = ( | ||||||||||||||||||||||||||||||||||||||||||
| 111 | strict => delete($options->{strict_method_check}), | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 189 | no_strict_method_check => delete($options->{no_strict_method_check}), | |||||||||||||||||||||||||||||||||||||||||
| 113 | allow_method_names_outside_object => $self->allow_method_names_outside_object, | ||||||||||||||||||||||||||||||||||||||||||
| 114 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 189 | return $self->tag_helpers->field_value($self->model, $attribute, \%options); | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 19 | ▶ | sub tag_errors_for_attribute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tag_errors_for_attribute: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 19 | my ($self, $attribute) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 19 | return $self->tag_helpers->field_errors($self->model, $attribute); | |||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 45 | ▶ | sub human_name_for_attribute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
human_name_for_attribute: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 45 | my ($self, $attribute) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 45 | ▶ | return $self->model->can('human_attribute_name') ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | $self->model->human_attribute_name($attribute) : | ||||||||||||||||||||||||||||||||||||||||||
| 127 | $self->tag_helpers->_humanize($attribute); | ||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 33 | ▶ | sub human_name_for_label { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
human_name_for_label: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 33 | my ($self, $label) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 132 | 33 | ▶ | return $self->model->can('human_label_name') ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | $self->model->human_label_name($label) : | ||||||||||||||||||||||||||||||||||||||||||
| 134 | $self->tag_helpers->_humanize($label); | ||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 186 | ▶ | sub attribute_has_errors { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
attribute_has_errors: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 186 | my ($self, $attribute) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 186 | ▶ | return $self->model->can('errors') && $self->model->errors->where($attribute) ? 1:0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->model->can("errors") and $self->model->errors->where($attribute)
MC/DC100%2/2
$self->model->can("errors") and $self->model->errors->where($attribute)
$self->model->can("errors")
$self->model->errors->where($attribute)
Truth table100%3/3
A and B
A= $self->model->can("errors")B= $self->model->errors->where($attribute)
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | # my $u = $fb->form_action->clone; $u->query_param_append('add_comment', 1); | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | sub form_action_for { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
form_action_for: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | my $params = pop @_ if (ref($_[-1])||'') eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
ref $_[-1] || ''
MC/DC0%0/1
ref $_[-1] || ''
ref $_[-1]
Truth table0%0/2
A
A= ref $_[-1]
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | my @path_parts = @_; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | my $url = $self->form_action->clone; | |||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | my @segments = $url->path_segments; | |||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | $url->query_param_append(%$params) if $params; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | $url->path_segments(@segments, @path_parts) if @path_parts; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | return $url; | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | # $fb->has_errors() | ||||||||||||||||||||||||||||||||||||||||||
| 158 | # $fb->model_errors($content) | ||||||||||||||||||||||||||||||||||||||||||
| 159 | # $fb->error_for_form(\&template) | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | sub form_has_errors { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
form_has_errors: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | my ($self) = shift; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | return '' unless $self->model->has_errors # There is at least one field with an error | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->model->has_errors or $self->_get_model_errors
MC/DC0%0/2
$self->model->has_errors or $self->_get_model_errors
$self->model->has_errors
$self->_get_model_errors
Truth table0%0/3
A or B
A= $self->model->has_errorsB= $self->_get_model_errors
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | || $self->_get_model_errors; # There is at least one error on the model itself | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | my $options = ref($_[0]) eq 'HASH' ? shift : +{}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | my $content = @_ ? shift : _t('invalid_form'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | return $content->($self->view, $self, $self->model) if ref($content) eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | $options = $self->merge_theme_field_opts('model_errors', undef, $options); | |||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | $content = $self->model->i18n->translate( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | $content, | ||||||||||||||||||||||||||||||||||||||||||
| 174 | scope=>'valiant.html.errors.messages', | ||||||||||||||||||||||||||||||||||||||||||
| 175 | default=>[ _t("errors.messages.invalid_form"), _t("messages.invalid_form") ], | ||||||||||||||||||||||||||||||||||||||||||
| 176 | ) if $self->model->i18n->is_i18n_tag($content); | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | return $self->tag_helpers->tags->div($options, $content); | |||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | sub _default_form_has_errors_content { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_default_form_has_errors_content: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | my ($self) = shift; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | my $message = $self->_generate_default_model_error; | |||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | my ($view, $self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | return $self->tag_helpers->div($message); | |||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | # Public methods for HTML generation | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | # $fb->model_errors() | ||||||||||||||||||||||||||||||||||||||||||
| 193 | # $fb->model_errors(\%options) | ||||||||||||||||||||||||||||||||||||||||||
| 194 | # $fb->model_errors(\%options, \&template) | ||||||||||||||||||||||||||||||||||||||||||
| 195 | # $fb->model_errors(\&template) | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | 7 | ▶ | sub model_errors { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
model_errors: called CC=12 SCAR=25.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 7 | my ($self) = shift; | |||||||||||||||||||||||||||||||||||||||||
| 199 | 7 | my ($options, $content) = (+{}, undef); | |||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 7 | ▶ | while(my $arg = shift) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 6 | ▶ | $options = $arg if (ref($arg)||'') eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
ref $arg || ''
MC/DC0%0/1
ref $arg || ''
ref $arg
Truth table50%1/2
A
A= ref $arg
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 6 | ▶ | $content = $arg if (ref($arg)||'') eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
ref $arg || ''
MC/DC0%0/1
ref $arg || ''
ref $arg
Truth table50%1/2
A
A= ref $arg
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 7 | $options = $self->merge_theme_field_opts('model_errors', undef, $options); | |||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 7 | my @errors = $self->_get_model_errors; | |||||||||||||||||||||||||||||||||||||||||
| 208 | 7 | my $show_message_on_field_errors = delete $options->{show_message_on_field_errors}; | |||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | 7 | ▶ | if( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->_model_has_errors and $show_message_on_field_errors
MC/DC50%1/2
$self->_model_has_errors and $show_message_on_field_errors
$self->_model_has_errors
$show_message_on_field_errors
Truth table66%2/3
A and B
A= $self->_model_has_errorsB= $show_message_on_field_errors
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | $self->_model_has_errors && # We have errors | ||||||||||||||||||||||||||||||||||||||||||
| 212 | # !scalar(@errors) && # but no model errorsS_VIEW | ||||||||||||||||||||||||||||||||||||||||||
| 213 | ($show_message_on_field_errors) # And a default model error | ||||||||||||||||||||||||||||||||||||||||||
| 214 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 215 | 2 | unshift @errors, $self->_generate_default_model_error($show_message_on_field_errors); | |||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 7 | ▶ | return '' unless @errors; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 7 | ▶ | my $max_errors = exists($options->{max_errors}) ? delete($options->{max_errors}) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 7 | ▶ | @errors = @errors[0..($max_errors-1)] if($max_errors); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 7 | ▶ | $content = $self->_default_model_errors_content($options) unless defined($content); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | 7 | my $error_content = $content->(@errors); | |||||||||||||||||||||||||||||||||||||||||
| 224 | 7 | return $error_content; | |||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 7 | ▶ | sub _model_has_errors { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_model_has_errors: called CC=2 SCAR=8.1
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 7 | ▶ | return $self->model->has_errors if $self->model->can('has_errors'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | 7 | ▶ | sub _get_model_errors { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_model_errors: called CC=2 SCAR=8.1
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 7 | ▶ | return my @errors = $self->model->errors->model_messages if $self->model->can('errors'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | return (); | |||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | 2 | ▶ | sub _generate_default_model_error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_default_model_error: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | 2 | my ($self, $tag) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 240 | 2 | ▶ | $tag = _t('invalid_form') if $tag eq '1'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 2 | ▶ | return $tag unless ref $tag; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | 1 | ▶ | return $self->DEFAULT_MODEL_ERROR_MSG_ON_FIELD_ERRORS unless $self->model->can('i18n'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 1 | return $self->model->i18n->translate( | |||||||||||||||||||||||||||||||||||||||||
| 244 | $tag, | ||||||||||||||||||||||||||||||||||||||||||
| 245 | scope=>'valiant.html.errors.messages', | ||||||||||||||||||||||||||||||||||||||||||
| 246 | default=>[ _t("errors.messages.$tag"), _t("messages.$tag") ], | ||||||||||||||||||||||||||||||||||||||||||
| 247 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | 6 | ▶ | sub _default_model_errors_content { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_default_model_errors_content: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 6 | my ($self, $options) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 252 | 6 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | 6 | my (@errors) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 254 | 6 | ▶ | if( scalar(@errors) == 1 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | 2 | return $self->tag_helpers->content_tag('div', $errors[0], $options); | |||||||||||||||||||||||||||||||||||||||||
| 256 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 257 | 4 | ▶ | return $self->tag_helpers->content_tag('ol', $options, sub { map { $self->tag_helpers->content_tag('li', $_) } @errors }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 260 | 6 | } | |||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | sub merge_theme { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
merge_theme: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | my ($self, %theme) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | $self->theme(+{ %{$self->theme}, %theme }); | |||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | 253 | ▶ | sub merge_theme_field_opts { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
merge_theme_field_opts: called CC=4 SCAR=16.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 253 | my ($self, $tag_type, $attribute, $existing) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 269 | 253 | my $theme = $self->theme; | |||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 253 | ▶ | if(exists $theme->{$tag_type}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | $existing = +{ %{$theme->{$tag_type}}, %$existing }; | |||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||
| 274 | 253 | ▶ | if($attribute && exists $theme->{attributes}{$attribute}{$tag_type}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$attribute and exists $theme->{"attributes"}{$attribute}{$tag_type}
MC/DC0%0/2
$attribute and exists $theme->{"attributes"}{$attribute}{$tag_type}
$attribute
exists $theme->{"attributes"}{$attribute}{$tag_type}
Truth table66%2/3
A and B
A= $attributeB= exists $theme->{"attributes"}{$attribute}{$tag_type}
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | $existing = +{ %{$theme->{attributes}{$attribute}{$tag_type}}, %$existing }; | |||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | 253 | return $existing; | |||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | # $fb->label($attribute) | ||||||||||||||||||||||||||||||||||||||||||
| 281 | # $fb->label($attribute, \%options) | ||||||||||||||||||||||||||||||||||||||||||
| 282 | # $fb->label($attribute, $content) | ||||||||||||||||||||||||||||||||||||||||||
| 283 | # $fb->label($attribute, \%options, $content) | ||||||||||||||||||||||||||||||||||||||||||
| 284 | # $fb->label($attribute, \&content); sub content { my ($translated_attribute) = @_; ... } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | # $fb->label($attribute, \%options, \&content); sub content { my ( $translated_attribute) = @_; ... } | ||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | 45 | ▶ | sub label { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
label: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | 45 | my ($self, $attribute) = (shift, shift); | |||||||||||||||||||||||||||||||||||||||||
| 289 | 45 | my ($options, $content) = (+{}, (my $translated_attribute = $self->human_name_for_attribute($attribute))); | |||||||||||||||||||||||||||||||||||||||||
| 290 | 45 | ▶ | while(my $arg = shift) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | 61 | ▶ | $options = $arg if (ref($arg)||'') eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $arg || ''
MC/DC100%1/1
ref $arg || ''
ref $arg
Truth table100%2/2
A
A= ref $arg
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | 61 | ▶ | $content = $arg if (ref($arg)||'') eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $arg || ''
MC/DC100%1/1
ref $arg || ''
ref $arg
Truth table100%2/2
A
A= ref $arg
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 61 | ▶ | $content = $arg if (ref(\$arg)||'') eq 'SCALAR'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
ref \$arg || ''
MC/DC0%0/1
ref \$arg || ''
ref \$arg
Truth table50%1/2
A
A= ref \$arg
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 45 | set_unless_defined(for => $options, $self->tag_id_for_attribute($attribute)); | |||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 45 | $options = $self->merge_theme_field_opts(label=>$attribute, $options); | |||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 45 | my $label =''; | |||||||||||||||||||||||||||||||||||||||||
| 301 | 45 | ▶ | if((ref($content)||'') eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $content || ''
MC/DC100%1/1
ref $content || ''
ref $content
Truth table100%2/2
A
A= ref $content
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 2 | ▶ | $label = $self->tag_helpers->label_tag($attribute, $self->process_options($attribute, $options), sub { $content->($translated_attribute) } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 304 | 43 | $label = $self->tag_helpers->label_tag($attribute, $content, $self->process_options($attribute, $options)); | |||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||
| 306 | 45 | return $label; | |||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | # $fb->errors_for($attribute) | ||||||||||||||||||||||||||||||||||||||||||
| 310 | # $fb->errors_for($attribute, \%options) | ||||||||||||||||||||||||||||||||||||||||||
| 311 | # $fb->errors_for($attribute, \%options, \&template) | ||||||||||||||||||||||||||||||||||||||||||
| 312 | # $fb->errors_for($attribute, \&template) | ||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | 19 | ▶ | sub errors_for { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
errors_for: called CC=14 SCAR=26.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | 19 | my ($self, $attribute) = (shift, shift); | |||||||||||||||||||||||||||||||||||||||||
| 316 | 19 | my ($options, $content) = (+{}, undef); | |||||||||||||||||||||||||||||||||||||||||
| 317 | 19 | ▶ | while(my $arg = shift) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 6 | ▶ | $options = $arg if (ref($arg)||'') eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
ref $arg || ''
MC/DC0%0/1
ref $arg || ''
ref $arg
Truth table50%1/2
A
A= ref $arg
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | 6 | ▶ | $content = $arg if (ref($arg)||'') eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
ref $arg || ''
MC/DC0%0/1
ref $arg || ''
ref $arg
Truth table50%1/2
A
A= ref $arg
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||
| 321 | 19 | $options = $self->merge_theme_field_opts(errors_for=>$attribute, $options); | |||||||||||||||||||||||||||||||||||||||||
| 322 | 19 | ▶ | my $show_empty = exists($options->{show_empty}) ? delete($options->{show_empty}) : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | 19 | ▶ | if($show_empty) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | 1 | ▶ | $options->{always_array} = 1 unless exists($options->{always_array}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | 19 | my @errors = $self->tag_errors_for_attribute($attribute); | |||||||||||||||||||||||||||||||||||||||||
| 328 | 19 | ▶ | return '' if scalar(@errors) == 0 && !$show_empty; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
scalar @errors == 0 and not $show_empty
MC/DC100%2/2
scalar @errors == 0 and not $show_empty
scalar @errors == 0
not $show_empty
Truth table100%3/3
A and not(B)
A= scalar @errors == 0B= not $show_empty
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | 17 | ▶ | my $max_errors = exists($options->{max_errors}) ? delete($options->{max_errors}) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | 17 | ▶ | @errors = @errors[0..($max_errors-1)] if($max_errors); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | 17 | $options = $self->process_options($attribute, $options); | |||||||||||||||||||||||||||||||||||||||||
| 333 | 17 | ▶ | $content = $self->_default_errors_for_content($attribute, $options) unless defined($content); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | 17 | my $response = $self->view->safe(''); | |||||||||||||||||||||||||||||||||||||||||
| 336 | 17 | $response = $content->(@errors);# if @errors; | |||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | 17 | return $response; | |||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | 15 | ▶ | sub _default_errors_for_content { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_default_errors_for_content: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 342 | 15 | my ($self, $attribute, $options) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 343 | 15 | ▶ | my $always_array = exists($options->{always_array}) ? delete($options->{always_array}) : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | 15 | my $id = $self->tag_id_for_attribute($attribute) . '_errors'; | |||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | 15 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | 15 | my (@errors) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 348 | 15 | my $response = ''; | |||||||||||||||||||||||||||||||||||||||||
| 349 | 15 | ▶ | if( !$always_array && (scalar(@errors) < 2) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $always_array and scalar @errors < 2
MC/DC100%2/2
not $always_array and scalar @errors < 2
not $always_array
scalar @errors < 2
Truth table100%3/3
not(A) and B
A= not $always_arrayB= scalar @errors < 2
| |||||||||||||||||||||||||||||||||||||||||||
| 350 | 11 | $response = $self->tag_helpers->content_tag('div', $errors[0], {%$options, id=>$id, data=>{error_param=>1}}); | |||||||||||||||||||||||||||||||||||||||||
| 351 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 352 | 4 | ▶ | if($always_array) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | 1 | ▶ | @errors = ('') unless @errors; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||
| 355 | 4 | my @li_content = map { $self->tag_helpers->content_tag('li', $_, { data=>{error_param=>1}}) } @errors; | |||||||||||||||||||||||||||||||||||||||||
| 356 | 4 | $response = $self->tag_helpers->content_tag('ol', $self->view->safe_concat(@li_content), {%$options, id=>$id, data=>{error_list=>1}}); | |||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||
| 358 | 15 | return $response; | |||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||
| 360 | 15 | } | |||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | 186 | ▶ | sub process_options { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_options: called CC=11 SCAR=34.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | 186 | my ($self, $attribute, $options) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||
| 365 | 186 | ▶ | if($options->{data}{remote}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | my $url = $self->form_action->clone; | |||||||||||||||||||||||||||||||||||||||||
| 367 | my $replace = exists($options->{data}{replace}) | ||||||||||||||||||||||||||||||||||||||||||
| 368 | ? $options->{data}{replace} | ||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | : '#'.$options->{id}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | $url->query_param(replace=>$replace); | |||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | $options->{data}{url} = $url; | |||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | ▶ | $options->{data}{method} ||= $self->form_method; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$options->{"data"}{"method"} ||= $self->form_method
MC/DC0%0/2
$options->{"data"}{"method"} ||= $self->form_method
$options->{"data"}{"method"}
$self->form_method
Truth table0%0/3
A ||= B
A= $options->{"data"}{"method"}B= $self->form_method
| |||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | $options->{data}{params} = $self->view->uri_escape(csrf_token => $self->csrf_token); | |||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||
| 377 | 186 | ▶ | if( ($self->attribute_has_errors($attribute)) && (my $errors_attrs = delete $options->{errors_attrs})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->attribute_has_errors($attribute) and my $errors_attrs = delete $options->{"errors_attrs"}
MC/DC100%2/2
$self->attribute_has_errors($attribute) and my $errors_attrs = delete $options->{"errors_attrs"}
$self->attribute_has_errors($attribute)
my $errors_attrs = delete $options->{"errors_attrs"}
Truth table100%3/3
A and B
A= $self->attribute_has_errors($attribute)B= my $errors_attrs = delete $options->{"errors_attrs"}
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | 1 | foreach my $key(keys %$errors_attrs) { | |||||||||||||||||||||||||||||||||||||||||
| 379 | 1 | ▶ | if(exists $options->{$key}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | 1 | ▶ | if( ($key eq 'data') || ($key eq 'aria') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$key eq "data" or $key eq "aria"
MC/DC0%0/2
$key eq "data" or $key eq "aria"
$key eq "data"
$key eq "aria"
Truth table33%1/3
A or B
A= $key eq "data"B= $key eq "aria"
| |||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | $options->{$key} = +{ %{$options->{$key}}, %{$errors_attrs->{$key}} }; | |||||||||||||||||||||||||||||||||||||||||
| 382 | } elsif($key eq 'class') { | ||||||||||||||||||||||||||||||||||||||||||
| 383 | 1 | $options->{$key} .= " $errors_attrs->{$key}"; | |||||||||||||||||||||||||||||||||||||||||
| 384 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | $options->{$key} .= $errors_attrs->{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||
| 387 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | $options->{$key} = $errors_attrs->{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||
| 392 | 186 | return $options; | |||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | # $fb->input($attribute, \%options) | ||||||||||||||||||||||||||||||||||||||||||
| 396 | # $fb->input($attribute) | ||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | 81 | ▶ | sub input { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
input: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 399 | 81 | ▶ | my ($self, $attribute, $options) = (shift, shift, (@_ ? shift : +{})); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 400 | 81 | ▶ | $options = $self->merge_theme_field_opts($options->{type} || 'input', $attribute, $options); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$options->{'type'} || 'input'
MC/DC100%1/1
$options->{'type'} || 'input'
$options->{'type'}
Truth table100%2/2
A
A= $options->{'type'}
| |||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||
| 402 | 81 | my %flags = (); | |||||||||||||||||||||||||||||||||||||||||
| 403 | 81 | ▶ | $flags{force_validity} = delete $options->{force_validity} if exists $options->{force_validity}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 404 | 81 | ▶ | $flags{errors_classes} = delete $options->{errors_classes} if exists $options->{errors_classes}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | 81 | my $response = $self->_input($attribute, $options, \%flags); | |||||||||||||||||||||||||||||||||||||||||
| 407 | 81 | return $response; | |||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | 81 | ▶ | sub _input { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_input: called CC=8 SCAR=21.0
| |||||||||||||||||||||||||||||||||||||||||||
| 411 | 81 | my ($self, $attribute, $html_attrs, $flags) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 412 | 81 | ▶ | my $model = $self->model->can('to_model') ? $self->model->to_model : $self->model; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 413 | 81 | my $valid = 1; | |||||||||||||||||||||||||||||||||||||||||
| 414 | 81 | ▶ | if(exists($flags->{force_validity})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | $valid = $flags->{force_validity}; | |||||||||||||||||||||||||||||||||||||||||
| 416 | } elsif($model->can('errors')) { | ||||||||||||||||||||||||||||||||||||||||||
| 417 | 72 | ▶ | $valid = $model->errors->where($attribute) ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | 16 | $html_attrs->{class} = join(' ', (grep { defined $_ } $html_attrs->{class}, $flags->{errors_classes})) | |||||||||||||||||||||||||||||||||||||||||
| 421 | 81 | ▶ | if $flags->{errors_classes} && !$valid; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$flags->{"errors_classes"} and not $valid
MC/DC50%1/2
$flags->{"errors_classes"} and not $valid
$flags->{"errors_classes"}
not $valid
Truth table66%2/3
A and not(B)
A= $flags->{"errors_classes"}B= not $valid
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | 81 | set_unless_defined(type => $html_attrs, 'text'); | |||||||||||||||||||||||||||||||||||||||||
| 424 | 81 | set_unless_defined(id => $html_attrs, $self->tag_id_for_attribute($attribute)); | |||||||||||||||||||||||||||||||||||||||||
| 425 | 81 | set_unless_defined(name => $html_attrs, $self->tag_name_for_attribute($attribute)); | |||||||||||||||||||||||||||||||||||||||||
| 426 | 81 | ▶ | $html_attrs->{value} = $self->tag_value_for_attribute($attribute) unless defined($html_attrs->{value}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 427 | 81 | $html_attrs = $self->process_options($attribute, $html_attrs); | |||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||
| 429 | 81 | return my $input_safe_string = $self->tag_helpers->input_tag($attribute, $html_attrs); | |||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||
| 432 | 4 | ▶ | sub password { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
password: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 433 | 4 | ▶ | my ($self, $attribute, $options) = (shift, shift, (@_ ? shift : +{})); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 434 | 4 | $options->{type} = 'password'; | |||||||||||||||||||||||||||||||||||||||||
| 435 | 4 | ▶ | $options->{value} = '' unless exists($options->{value}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 436 | 4 | return $self->input($attribute, $options); | |||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | 13 | ▶ | sub hidden { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hidden: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 440 | 13 | ▶ | my ($self, $attribute, $options) = (shift, shift, (@_ ? shift : +{})); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | 13 | $options->{type} = 'hidden'; | |||||||||||||||||||||||||||||||||||||||||
| 442 | 13 | return $self->input($attribute, $options); | |||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||
| 445 | 3 | ▶ | sub text_area { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
text_area: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 446 | 3 | ▶ | my ($self, $attribute, $options) = (shift, shift, (@_ ? shift : +{})); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | 3 | $options = $self->merge_theme_field_opts('text_area', $attribute, $options); | |||||||||||||||||||||||||||||||||||||||||
| 448 | 3 | ▶ | my $errors_classes = exists($options->{errors_classes}) ? delete($options->{errors_classes}) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||
| 450 | 3 | ▶ | $options->{class} = join(' ', (grep { defined $_ } $options->{class}, $errors_classes)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$errors_classes and $self->model->can("errors") and $self->model->errors->where($attribute)
$errors_classes and $self->model->can("errors")
MC/DC33%1/3
$errors_classes and $self->model->can("errors") and $self->model->errors->where($attribute)
$errors_classes
$self->model->can("errors")
$self->model->errors->where($attribute)
Truth table50%2/4
A and B and C
A= $errors_classesB= $self->model->can("errors")C= $self->model->errors->where($attribute)
| |||||||||||||||||||||||||||||||||||||||||||
| 451 | if $errors_classes && $self->model->can('errors') && $self->model->errors->where($attribute); | ||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | 3 | set_unless_defined(id => $options, $self->tag_id_for_attribute($attribute)); | |||||||||||||||||||||||||||||||||||||||||
| 454 | 3 | return $self->tag_helpers->text_area_tag( | |||||||||||||||||||||||||||||||||||||||||
| 455 | $self->tag_name_for_attribute($attribute), | ||||||||||||||||||||||||||||||||||||||||||
| 456 | $self->tag_value_for_attribute($attribute), | ||||||||||||||||||||||||||||||||||||||||||
| 457 | $self->process_options($attribute, $options), | ||||||||||||||||||||||||||||||||||||||||||
| 458 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||
| 461 | 22 | ▶ | sub checkbox { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
checkbox: called CC=15 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 462 | 22 | my ($self, $attribute) = (shift, shift); | |||||||||||||||||||||||||||||||||||||||||
| 463 | 22 | ▶ | my $options = (ref($_[0])||'') eq 'HASH' ? shift(@_) : +{}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $_[0] || ''
MC/DC100%1/1
ref $_[0] || ''
ref $_[0]
Truth table100%2/2
A
A= ref $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 464 | 22 | $options = $self->merge_theme_field_opts('checkbox', $attribute, $options); | |||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||
| 466 | 22 | ▶ | my $checked_value = @_ ? shift : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 467 | 22 | ▶ | my $unchecked_value = @_ ? shift : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 468 | 22 | ▶ | my $errors_classes = exists($options->{errors_classes}) ? delete($options->{errors_classes}) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 469 | 22 | ▶ | my $show_hidden_unchecked = exists($options->{include_hidden}) ? delete($options->{include_hidden}) : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 470 | 22 | my $name = $self->tag_name_for_attribute($attribute); | |||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||
| 472 | 22 | my $checked = 0; | |||||||||||||||||||||||||||||||||||||||||
| 473 | 22 | ▶ | if(exists($options->{checked})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 474 | 16 | $checked = delete $options->{checked}; | |||||||||||||||||||||||||||||||||||||||||
| 475 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 476 | 6 | ▶ | $checked = $self->tag_value_for_attribute($attribute) ? 1:0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||
| 479 | 22 | $options->{type} = 'checkbox'; | |||||||||||||||||||||||||||||||||||||||||
| 480 | 22 | ▶ | $options->{value} = $checked_value unless exists($options->{value}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 481 | 22 | ▶ | $options->{class} = join(' ', (grep { defined $_ } $options->{class}, $errors_classes)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$errors_classes and $self->model->can("errors") and $self->model->errors->where($attribute)
$errors_classes and $self->model->can("errors")
MC/DC33%1/3
$errors_classes and $self->model->can("errors") and $self->model->errors->where($attribute)
$errors_classes
$self->model->can("errors")
$self->model->errors->where($attribute)
Truth table50%2/4
A and B and C
A= $errors_classesB= $self->model->can("errors")C= $self->model->errors->where($attribute)
| |||||||||||||||||||||||||||||||||||||||||||
| 482 | if $errors_classes && $self->model->can('errors') && $self->model->errors->where($attribute); | ||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||
| 484 | 22 | set_unless_defined(id => $options, $self->tag_id_for_attribute($attribute)); | |||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||
| 486 | 22 | my $checkbox = $self->tag_helpers->checkbox_tag( | |||||||||||||||||||||||||||||||||||||||||
| 487 | $name, | ||||||||||||||||||||||||||||||||||||||||||
| 488 | $checked_value, | ||||||||||||||||||||||||||||||||||||||||||
| 489 | $checked, | ||||||||||||||||||||||||||||||||||||||||||
| 490 | $self->process_options($attribute, $options), | ||||||||||||||||||||||||||||||||||||||||||
| 491 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||
| 493 | 22 | ▶ | if($show_hidden_unchecked) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 494 | 3 | ▶ | my $hidden_name = exists($options->{name}) ? $options->{name} : $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 495 | 3 | my $hidden_checkbox = $self->tag_helpers->tag('input', +{type=>'hidden', name=>$hidden_name, value=>$unchecked_value}); | |||||||||||||||||||||||||||||||||||||||||
| 496 | 3 | $checkbox = $self->tag_helpers->join_tags($hidden_checkbox, $checkbox); | |||||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||
| 499 | 22 | return $checkbox; | |||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||
| 502 | #radio_button(object_name, method, tag_value, options = {}) | ||||||||||||||||||||||||||||||||||||||||||
| 503 | 14 | ▶ | sub radio_button { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
radio_button: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 504 | 14 | my ($self, $attribute) = (shift, shift); | |||||||||||||||||||||||||||||||||||||||||
| 505 | 14 | ▶ | my $options = (ref($_[-1])||'') eq 'HASH' ? pop(@_) : +{}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $_[-1] || ''
MC/DC100%1/1
ref $_[-1] || ''
ref $_[-1]
Truth table100%2/2
A
A= ref $_[-1]
| |||||||||||||||||||||||||||||||||||||||||||
| 506 | 14 | $options = $self->merge_theme_field_opts('radio_button', $attribute, $options); | |||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||
| 508 | 14 | ▶ | my $value = @_ ? shift : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||
| 510 | 14 | $options->{type} = 'radio'; | |||||||||||||||||||||||||||||||||||||||||
| 511 | 14 | ▶ | $options->{value} = $value unless exists($options->{value}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 512 | 14 | ▶ | $options->{checked} = do { $self->tag_value_for_attribute($attribute) eq $value ? 1:0 } unless exists($options->{checked}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 513 | 14 | ▶ | $options->{id} = $self->tag_id_for_attribute($attribute, $value) unless exists($options->{id}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||
| 515 | 14 | return $self->input($attribute, $self->process_options($attribute, $options)); | |||||||||||||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||
| 518 | 6 | ▶ | sub date_field { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
date_field: called CC=7 SCAR=20.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 519 | 6 | my ($self, $attribute, $options) = (@_, +{}); | |||||||||||||||||||||||||||||||||||||||||
| 520 | 6 | my $value = $self->tag_value_for_attribute($attribute); | |||||||||||||||||||||||||||||||||||||||||
| 521 | 6 | $options = $self->merge_theme_field_opts('date_field', $attribute, $options); | |||||||||||||||||||||||||||||||||||||||||
| 522 | 6 | $options->{type} = 'date'; | |||||||||||||||||||||||||||||||||||||||||
| 523 | 6 | ▶ | $options->{value} ||= Scalar::Util::blessed($value) ? $value->ymd : $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$options->{"value"} ||= builtin::blessed($value) ? $value->ymd : $value
MC/DC0%0/2
$options->{"value"} ||= builtin::blessed($value) ? $value->ymd : $value
$options->{"value"}
builtin::blessed($value) ? $value->ymd : $value
Truth table33%1/3
A ||= B
A= $options->{"value"}B= builtin::blessed($value) ? $value->ymd : $value
| |||||||||||||||||||||||||||||||||||||||||||
| 524 | 6 | ▶ | $options->{min} = $options->{min}->ymd if exists($options->{min}) && Scalar::Util::blessed($options->{min}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $options->{"min"} and builtin::blessed($options->{"min"})
MC/DC50%1/2
exists $options->{"min"} and builtin::blessed($options->{"min"})
exists $options->{"min"}
builtin::blessed($options->{"min"})
Truth table66%2/3
A and B
A= exists $options->{"min"}B= builtin::blessed($options->{"min"})
| |||||||||||||||||||||||||||||||||||||||||||
| 525 | 6 | ▶ | $options->{max} = $options->{max}->ymd if exists($options->{max}) && Scalar::Util::blessed($options->{max}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $options->{"max"} and builtin::blessed($options->{"max"})
MC/DC50%1/2
exists $options->{"max"} and builtin::blessed($options->{"max"})
exists $options->{"max"}
builtin::blessed($options->{"max"})
Truth table66%2/3
A and B
A= exists $options->{"max"}B= builtin::blessed($options->{"max"})
| |||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||
| 527 | 6 | return $self->input($attribute, $options); | |||||||||||||||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||
| 530 | 1 | ▶ | sub datetime_local_field { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
datetime_local_field: called CC=7 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 531 | 1 | my ($self, $attribute, $options) = (@_, +{}); | |||||||||||||||||||||||||||||||||||||||||
| 532 | 1 | my $value = $self->tag_value_for_attribute($attribute); | |||||||||||||||||||||||||||||||||||||||||
| 533 | 1 | $options = $self->merge_theme_field_opts('datetime_local_field', $attribute, $options); | |||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||
| 535 | 1 | $options->{type} = 'datetime-local'; | |||||||||||||||||||||||||||||||||||||||||
| 536 | 1 | ▶ | $options->{value} ||= Scalar::Util::blessed($value) ? $value->strftime('%Y-%m-%dT%T') : $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$options->{"value"} ||= builtin::blessed($value) ? $value->strftime("%Y-%m-%dT%T") : $value
MC/DC0%0/2
$options->{"value"} ||= builtin::blessed($value) ? $value->strftime("%Y-%m-%dT%T") : $value
$options->{"value"}
builtin::blessed($value) ? $value->strftime("%Y-%m-%dT%T") : $value
Truth table33%1/3
A ||= B
A= $options->{"value"}B= builtin::blessed($value) ? $value->strftime("%Y-%m-%dT%T") : $value
| |||||||||||||||||||||||||||||||||||||||||||
| 537 | 1 | ▶ | $options->{min} = $options->{min}->strftime('%Y-%m-%dT%T') if exists($options->{min}) && Scalar::Util::blessed($options->{min}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $options->{"min"} and builtin::blessed($options->{"min"})
MC/DC0%0/2
exists $options->{"min"} and builtin::blessed($options->{"min"})
exists $options->{"min"}
builtin::blessed($options->{"min"})
Truth table33%1/3
A and B
A= exists $options->{"min"}B= builtin::blessed($options->{"min"})
| |||||||||||||||||||||||||||||||||||||||||||
| 538 | 1 | ▶ | $options->{max} = $options->{max}->strftime('%Y-%m-%dT%T') if exists($options->{max}) && Scalar::Util::blessed($options->{max}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $options->{"max"} and builtin::blessed($options->{"max"})
MC/DC0%0/2
exists $options->{"max"} and builtin::blessed($options->{"max"})
exists $options->{"max"}
builtin::blessed($options->{"max"})
Truth table33%1/3
A and B
A= exists $options->{"max"}B= builtin::blessed($options->{"max"})
| |||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||
| 540 | 1 | return $self->input($attribute, $options); | |||||||||||||||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||
| 543 | 2 | ▶ | sub time_field { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
time_field: called CC=5 SCAR=16.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 544 | 2 | my ($self, $attribute, $options) = (@_, +{}); | |||||||||||||||||||||||||||||||||||||||||
| 545 | 2 | my $value = $self->tag_value_for_attribute($attribute); | |||||||||||||||||||||||||||||||||||||||||
| 546 | 2 | $options = $self->merge_theme_field_opts('time_field', $attribute, $options); | |||||||||||||||||||||||||||||||||||||||||
| 547 | 2 | ▶ | my $format = (exists($options->{include_seconds}) && !delete($options->{include_seconds})) ? '%H:%M' : '%T.%3N'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $options->{"include_seconds"} and not delete $options->{"include_seconds"}
MC/DC50%1/2
exists $options->{"include_seconds"} and not delete $options->{"include_seconds"}
exists $options->{"include_seconds"}
not delete $options->{"include_seconds"}
Truth table66%2/3
A and not(B)
A= exists $options->{"include_seconds"}B= not delete $options->{"include_seconds"}
| |||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||
| 549 | 2 | $options->{type} = 'time'; | |||||||||||||||||||||||||||||||||||||||||
| 550 | 2 | ▶ | $options->{value} ||= Scalar::Util::blessed($value) ? $value->strftime($format) : $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$options->{"value"} ||= builtin::blessed($value) ? $value->strftime($format) : $value
MC/DC0%0/2
$options->{"value"} ||= builtin::blessed($value) ? $value->strftime($format) : $value
$options->{"value"}
builtin::blessed($value) ? $value->strftime($format) : $value
Truth table33%1/3
A ||= B
A= $options->{"value"}B= builtin::blessed($value) ? $value->strftime($format) : $value
| |||||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||
| 552 | 2 | return $self->input($attribute, $options); | |||||||||||||||||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||
| 555 | 2 | ▶ | sub submit { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
submit: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 556 | 2 | my ($self) = shift; | |||||||||||||||||||||||||||||||||||||||||
| 557 | 2 | ▶ | my $options = (ref($_[-1])||'') eq 'HASH' ? pop(@_) : +{}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $_[-1] || ''
MC/DC100%1/1
ref $_[-1] || ''
ref $_[-1]
Truth table100%2/2
A
A= ref $_[-1]
| |||||||||||||||||||||||||||||||||||||||||||
| 558 | 2 | ▶ | my $value = @_ ? shift(@_) : $self->_submit_default_value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 559 | 2 | $options = $self->merge_theme_field_opts('submit', undef, $options); | |||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||
| 561 | 2 | return $self->tag_helpers->submit_tag($value, $options); | |||||||||||||||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||
| 564 | 1 | ▶ | sub _submit_default_value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_submit_default_value: called CC=4 SCAR=14.4
| |||||||||||||||||||||||||||||||||||||||||||
| 565 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 566 | 1 | ▶ | my $model = $self->model->can('to_model') ? $self->model->to_model : $self->model; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 567 | 1 | ▶ | my $key = $model->can('in_storage') ? ( $model->in_storage ? 'update':'create' ) : 'submit'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 568 | 1 | my $model_placeholder = $self->tag_helpers->_humanize($self->name); | |||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||
| 570 | 1 | my @defaults = (); | |||||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||||||
| 572 | 1 | push @defaults, _t "formbuilder.submit.@{[ $self->name ]}.${key}"; | |||||||||||||||||||||||||||||||||||||||||
| 573 | 1 | push @defaults, _t "formbuilder.submit.${key}"; | |||||||||||||||||||||||||||||||||||||||||
| 574 | 1 | push @defaults, "@{[ $self->tag_helpers->_humanize($key) ]} ${model_placeholder}"; | |||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||
| 576 | 1 | return $self->model->i18n->translate( | |||||||||||||||||||||||||||||||||||||||||
| 577 | shift(@defaults), | ||||||||||||||||||||||||||||||||||||||||||
| 578 | model=>$model_placeholder, | ||||||||||||||||||||||||||||||||||||||||||
| 579 | default=>\@defaults, | ||||||||||||||||||||||||||||||||||||||||||
| 580 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||||
| 583 | # ->button($name, \%attrs, \&block) | ||||||||||||||||||||||||||||||||||||||||||
| 584 | # ->button($name, \%attrs, $content) | ||||||||||||||||||||||||||||||||||||||||||
| 585 | # ->button($name, \&block) | ||||||||||||||||||||||||||||||||||||||||||
| 586 | # ->button($name, $content) | ||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||
| 588 | 5 | ▶ | sub button { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
button: called CC=8 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 589 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 590 | 5 | my $attribute = shift; | |||||||||||||||||||||||||||||||||||||||||
| 591 | 5 | ▶ | my $attrs = (ref($_[0])||'') eq 'HASH' ? shift(@_) : +{}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $_[0] || ''
MC/DC100%1/1
ref $_[0] || ''
ref $_[0]
Truth table100%2/2
A
A= ref $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 592 | 5 | my $content = shift; | |||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||
| 594 | 5 | ▶ | $attrs->{type} = 'submit' unless exists($attrs->{type}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 595 | 5 | ▶ | $attrs->{value} = $self->tag_value_for_attribute($attribute, $attrs) unless exists($attrs->{value}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 596 | 5 | ▶ | $attrs->{name} = $self->tag_name_for_attribute($attribute) unless exists($attrs->{name}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 597 | 5 | ▶ | $attrs->{id} = $self->tag_id_for_attribute($attribute) unless exists($attrs->{id}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 598 | 5 | $attrs = $self->merge_theme_field_opts('button', $attribute, $attrs); | |||||||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||||||
| 600 | 5 | ▶ | return ref($content) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 601 | $self->tag_helpers->button_tag($attrs, $content) : | ||||||||||||||||||||||||||||||||||||||||||
| 602 | $self->tag_helpers->button_tag($content, $self->process_options($attribute, $attrs)); | ||||||||||||||||||||||||||||||||||||||||||
| 603 | } | ||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||
| 605 | 6 | ▶ | sub legend { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
legend: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 606 | 6 | my ($self) = shift; | |||||||||||||||||||||||||||||||||||||||||
| 607 | 6 | my $value = my $default_value = $self->_legend_default_value; | |||||||||||||||||||||||||||||||||||||||||
| 608 | 6 | my $options = +{}; | |||||||||||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||||||||||||
| 610 | 6 | ▶ | $value = pop(@_) if (ref($_[-1])||'') eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $_[-1] || ''
MC/DC100%1/1
ref $_[-1] || ''
ref $_[-1]
Truth table100%2/2
A
A= ref $_[-1]
| |||||||||||||||||||||||||||||||||||||||||||
| 611 | 6 | ▶ | $options = pop(@_) if (ref($_[-1])||'') eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $_[-1] || ''
MC/DC100%1/1
ref $_[-1] || ''
ref $_[-1]
Truth table100%2/2
A
A= ref $_[-1]
| |||||||||||||||||||||||||||||||||||||||||||
| 612 | 6 | ▶ | $value = shift(@_) if @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 613 | 6 | ▶ | $value = $value->($default_value) if ((ref($value)||'') eq 'CODE'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $value || ''
MC/DC100%1/1
ref $value || ''
ref $value
Truth table100%2/2
A
A= ref $value
| |||||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||
| 615 | 6 | return $self->tag_helpers->legend_tag($value, $options); | |||||||||||||||||||||||||||||||||||||||||
| 616 | } | ||||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||
| 618 | 0 | ▶ | sub legend_for { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
legend_for: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 619 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | my $attribute = shift; | |||||||||||||||||||||||||||||||||||||||||
| 621 | 0 | ▶ | my $attrs = (ref($_[0])||'') eq 'HASH' ? shift(@_) : +{}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
ref $_[0] || ''
MC/DC0%0/1
ref $_[0] || ''
ref $_[0]
Truth table0%0/2
A
A= ref $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | ▶ | my $content = @_ ? shift(@_) : $self->human_name_for_attribute($attribute); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | ▶ | $attrs->{id} = "@{[ $self->tag_id_for_attribute($attribute) ]}_legend" unless exists($attrs->{id}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 625 | 0 | $attrs = $self->merge_theme_field_opts('legend_for', $attribute, $attrs); | |||||||||||||||||||||||||||||||||||||||||
| 626 | 0 | return $self->tag_helpers->legend_tag($content, $attrs); | |||||||||||||||||||||||||||||||||||||||||
| 627 | } | ||||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||
| 629 | 6 | ▶ | sub _legend_default_value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_legend_default_value: called CC=5 SCAR=17.2
| |||||||||||||||||||||||||||||||||||||||||||
| 630 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 631 | 6 | ▶ | my $model = $self->model->can('to_model') ? $self->model->to_model : $self->model; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 632 | 6 | ▶ | my $key = $model->can('in_storage') ? ( $model->in_storage ? 'update':'create' ) : 'new'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 633 | 6 | my $model_placeholder = $self->tag_helpers->_humanize($self->name); | |||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||
| 635 | 6 | my @defaults = (); | |||||||||||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | ▶ | return "@{[ $self->tag_helpers->_humanize($key) ]} ${model_placeholder}" unless $self->model->can('i18n'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||||||||||||||||
| 639 | 6 | push @defaults, _t "formbuilder.legend.@{[ $self->name ]}.${key}"; | |||||||||||||||||||||||||||||||||||||||||
| 640 | 6 | push @defaults, _t "formbuilder.legend.${key}"; | |||||||||||||||||||||||||||||||||||||||||
| 641 | 6 | push @defaults, "@{[ $self->tag_helpers->_humanize($key) ]} ${model_placeholder}"; | |||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||
| 643 | 6 | return $self->model->i18n->translate( | |||||||||||||||||||||||||||||||||||||||||
| 644 | shift(@defaults), | ||||||||||||||||||||||||||||||||||||||||||
| 645 | model=>$model_placeholder, | ||||||||||||||||||||||||||||||||||||||||||
| 646 | default=>\@defaults, | ||||||||||||||||||||||||||||||||||||||||||
| 647 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||||
| 650 | # fields_for($related_attribute, ?\%options?, \&block) | ||||||||||||||||||||||||||||||||||||||||||
| 651 | 2 | ▶ | sub fields_for { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fields_for: called CC=32 SCAR=42.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 652 | 2 | my ($self, $related_attribute) = (shift, shift); | |||||||||||||||||||||||||||||||||||||||||
| 653 | 2 | ▶ | my $options = (ref($_[0])||'') eq 'HASH' ? shift(@_) : +{}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
ref $_[0] || ''
MC/DC0%0/1
ref $_[0] || ''
ref $_[0]
Truth table50%1/2
A
A= ref $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 654 | 2 | ▶ | my $codeblock = (ref($_[0])||'') eq 'CODE' ? shift(@_) : die "Missing required code block"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
ref $_[0] || ''
MC/DC0%0/1
ref $_[0] || ''
ref $_[0]
Truth table50%1/2
A
A= ref $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 655 | 2 | ▶ | my $finally_block = (ref($_[0])||'') eq 'CODE' ? shift(@_) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $_[0] || ''
MC/DC100%1/1
ref $_[0] || ''
ref $_[0]
Truth table100%2/2
A
A= ref $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||||||||||||||||
| 657 | 2 | ▶ | $options->{builder} = $self->options->{builder} if !exists($options->{builder}) && !defined($options->{builder}) && defined($self->options->{builder}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not exists $options->{"builder"} || defined $options->{"builder"} and defined $self->options->{"builder"}
exists $options->{'builder'} || defined $options->{'builder'}
MC/DC0%0/3
not exists $options->{"builder"} || defined $options->{"builder"} and defined $self->options->{"builder"}
exists $options->{'builder'}
defined $options->{'builder'}
defined $self->options->{"builder"}
Truth table25%1/4
not(A || B) and C
A= exists $options->{'builder'}B= defined $options->{'builder'}C= defined $self->options->{"builder"}
| |||||||||||||||||||||||||||||||||||||||||||
| 658 | 2 | ▶ | $options->{include_id} = $self->options->{include_id} if !exists($options->{include_id}) && !defined($options->{include_id}) && defined($self->options->{include_id}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not exists $options->{"include_id"} || defined $options->{"include_id"} and defined $self->options->{"include_id"}
exists $options->{'include_id'} || defined $options->{'include_id'}
MC/DC0%0/3
not exists $options->{"include_id"} || defined $options->{"include_id"} and defined $self->options->{"include_id"}
exists $options->{'include_id'}
defined $options->{'include_id'}
defined $self->options->{"include_id"}
Truth table25%1/4
not(A || B) and C
A= exists $options->{'include_id'}B= defined $options->{'include_id'}C= defined $self->options->{"include_id"}
| |||||||||||||||||||||||||||||||||||||||||||
| 659 | 2 | ▶ | $options->{namespace} = $self->namespace if $self->has_namespace; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 660 | 2 | $options->{parent_builder} = $self; | |||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||
| 662 | 2 | my $related_record; | |||||||||||||||||||||||||||||||||||||||||
| 663 | 2 | ▶ | if(Scalar::Util::blessed($related_attribute)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 664 | 0 | $related_record = $related_attribute; | |||||||||||||||||||||||||||||||||||||||||
| 665 | 0 | $related_attribute = $related_record->model_name->param_key; | |||||||||||||||||||||||||||||||||||||||||
| 666 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 667 | 2 | $related_record = $self->tag_value_for_attribute($related_attribute); | |||||||||||||||||||||||||||||||||||||||||
| 668 | } | ||||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||||
| 670 | my $builder_name = exists($options->{scope}) | ||||||||||||||||||||||||||||||||||||||||||
| 671 | ? delete($options->{scope}) | ||||||||||||||||||||||||||||||||||||||||||
| 672 | 2 | ▶ | : $self->name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 673 | my $attribute_name = exists($options->{as}) | ||||||||||||||||||||||||||||||||||||||||||
| 674 | ? delete($options->{as}) | ||||||||||||||||||||||||||||||||||||||||||
| 675 | 2 | ▶ | : $related_attribute; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 676 | 2 | my $name = "${builder_name}.${attribute_name}"; | |||||||||||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||||||||||||
| 678 | 2 | ▶ | $related_record = $related_record->to_model if Scalar::Util::blessed($related_record) && $related_record->can('to_model'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($related_record) and $related_record->can("to_model")
MC/DC0%0/2
builtin::blessed($related_record) and $related_record->can("to_model")
builtin::blessed($related_record)
$related_record->can("to_model")
Truth table66%2/3
A and B
A= builtin::blessed($related_record)B= $related_record->can("to_model")
| |||||||||||||||||||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||||||||||||||||
| 680 | # Coerce an array into a collection. Not sure if we want this here or not TBH... | ||||||||||||||||||||||||||||||||||||||||||
| 681 | 2 | ▶ | $related_record = $self->tag_helpers->array_to_collection(map { $_->can('to_model') ? $_->to_model : $_ } @$related_record) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%1/2
ref $related_record || ''
MC/DC0%0/1
ref $related_record || ''
ref $related_record
Truth table50%1/2
A
A= ref $related_record
| |||||||||||||||||||||||||||||||||||||||||||
| 682 | if (ref($related_record)||'') eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||||||||||
| 684 | # Ok is the related record a collection or something else. | ||||||||||||||||||||||||||||||||||||||||||
| 685 | 2 | ▶ | if($related_record->can('next')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 686 | 1 | my @output = (); | |||||||||||||||||||||||||||||||||||||||||
| 687 | 1 | ▶ | my $explicit_child_index = exists($options->{child_index}) ? $options->{child_index} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||||||||||||||||
| 689 | 1 | ▶ | while(my $child_model = $related_record->next) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 690 | 3 | ▶ | if(defined($explicit_child_index)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 691 | 0 | ▶ | $options->{child_index} = $options->{child_index}->($child_model) if ref() eq 'CODE'; # allow for callback version of this | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 692 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 693 | 3 | $options->{child_index} = $self->nested_child_index($related_attribute); | |||||||||||||||||||||||||||||||||||||||||
| 694 | } | ||||||||||||||||||||||||||||||||||||||||||
| 695 | 3 | my $nested = $self->fields_for_nested_model("${name}[@{[ $options->{child_index} ]}]", $child_model, $options, $codeblock); | |||||||||||||||||||||||||||||||||||||||||
| 696 | 3 | push @output, $nested; | |||||||||||||||||||||||||||||||||||||||||
| 697 | } | ||||||||||||||||||||||||||||||||||||||||||
| 698 | 1 | ▶ | $related_record->reset if $related_record->can('reset'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 699 | 1 | ▶ | if($finally_block) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 700 | 1 | ▶ | my $finally_model = $related_record->can('build') ? $related_record->build : die "Can't have a finally block if the collection doesn't support 'build'"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 701 | 1 | ▶ | if(defined($explicit_child_index)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | ▶ | $options->{child_index} = $options->{child_index}->($finally_model) if ref() eq 'CODE'; # allow for callback version of this | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 703 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 704 | 1 | $options->{child_index} = $self->nested_child_index($related_attribute); | |||||||||||||||||||||||||||||||||||||||||
| 705 | } | ||||||||||||||||||||||||||||||||||||||||||
| 706 | 1 | my $finally_content = $self->fields_for_nested_model("${name}[@{[ $options->{child_index} ]}]", $finally_model, $options, $finally_block); | |||||||||||||||||||||||||||||||||||||||||
| 707 | 1 | push @output, $finally_content; | |||||||||||||||||||||||||||||||||||||||||
| 708 | } | ||||||||||||||||||||||||||||||||||||||||||
| 709 | 1 | return $self->tag_helpers->join_tags(@output); | |||||||||||||||||||||||||||||||||||||||||
| 710 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 711 | 1 | return $self->fields_for_nested_model($name, $related_record, $options, $codeblock); | |||||||||||||||||||||||||||||||||||||||||
| 712 | } | ||||||||||||||||||||||||||||||||||||||||||
| 713 | } | ||||||||||||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||||||||||||
| 715 | 5 | ▶ | sub fields_for_nested_model { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fields_for_nested_model: called CC=5 SCAR=19.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 716 | 5 | my ($self, $name, $model, $options, $codeblock) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 717 | 5 | my $emit_hidden_id = 0; | |||||||||||||||||||||||||||||||||||||||||
| 718 | 5 | ▶ | $model = $model->to_model if $model->can('to_model'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||||||
| 720 | 5 | ▶ | if($model->can('in_storage') && $model->in_storage) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$model->can("in_storage") and $model->in_storage
MC/DC0%0/2
$model->can("in_storage") and $model->in_storage
$model->can("in_storage")
$model->in_storage
Truth table33%1/3
A and B
A= $model->can("in_storage")B= $model->in_storage
| |||||||||||||||||||||||||||||||||||||||||||
| 721 | 0 | ▶ | $emit_hidden_id = exists($options->{include_id}) ? $options->{include_id} : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 722 | } | ||||||||||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||||||||||
| 724 | 5 | ▶ | return $self->tag_helpers->fields_for($name, $model, $options, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.3
| |||||||||||||||||||||||||||||||||||||||||||
| 725 | 5 | my $view = shift; | |||||||||||||||||||||||||||||||||||||||||
| 726 | 5 | my $fb = shift; | |||||||||||||||||||||||||||||||||||||||||
| 727 | 5 | my @output = $codeblock->($view, $fb, $model); | |||||||||||||||||||||||||||||||||||||||||
| 728 | 5 | ▶ | if(@output && $emit_hidden_id) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@output and $emit_hidden_id
MC/DC0%0/2
@output and $emit_hidden_id
@output
$emit_hidden_id
Truth table33%1/3
A and B
A= @outputB= $emit_hidden_id
| |||||||||||||||||||||||||||||||||||||||||||
| 729 | 0 | push @output, $fb->emit_hidden_ids; | |||||||||||||||||||||||||||||||||||||||||
| 730 | } | ||||||||||||||||||||||||||||||||||||||||||
| 731 | 5 | return $self->tag_helpers->join_tags(@output); | |||||||||||||||||||||||||||||||||||||||||
| 732 | 5 | }); | |||||||||||||||||||||||||||||||||||||||||
| 733 | } | ||||||||||||||||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||||||||||||||||
| 735 | ## TODO this seems very much tied to DBIx::Class | ||||||||||||||||||||||||||||||||||||||||||
| 736 | 0 | ▶ | sub emit_hidden_ids { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
emit_hidden_ids: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 737 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 738 | 0 | ▶ | my $model = $self->model->can('to_model') ? $self->model->to_model : $self->model; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||||||||||||||||
| 740 | 0 | ▶ | return '' unless $model->can('primary_columns'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 741 | |||||||||||||||||||||||||||||||||||||||||||
| 742 | 0 | my @output = (); | |||||||||||||||||||||||||||||||||||||||||
| 743 | 0 | foreach my $id_field ($model->primary_columns) { | |||||||||||||||||||||||||||||||||||||||||
| 744 | 0 | push @output, $self->hidden($id_field); | |||||||||||||||||||||||||||||||||||||||||
| 745 | } | ||||||||||||||||||||||||||||||||||||||||||
| 746 | 0 | return $self->tag_helpers->join_tags(@output); | |||||||||||||||||||||||||||||||||||||||||
| 747 | } | ||||||||||||||||||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||||||||||||||||
| 749 | 8 | ▶ | sub select { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
select: called CC=44 SCAR=41.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 750 | 8 | my ($self, $attribute_proto) = (shift, shift); | |||||||||||||||||||||||||||||||||||||||||
| 751 | 8 | ▶ | my $block = (ref($_[-1])||'') eq 'CODE' ? pop(@_) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
ref $_[-1] || ''
MC/DC0%0/1
ref $_[-1] || ''
ref $_[-1]
Truth table50%1/2
A
A= ref $_[-1]
| |||||||||||||||||||||||||||||||||||||||||||
| 752 | 8 | ▶ | my $options = (ref($_[-1])||'') eq 'HASH' ? pop(@_) : +{}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $_[-1] || ''
MC/DC100%1/1
ref $_[-1] || ''
ref $_[-1]
Truth table100%2/2
A
A= ref $_[-1]
| |||||||||||||||||||||||||||||||||||||||||||
| 753 | 8 | $options = $self->merge_theme_field_opts('select', undef, $options); | |||||||||||||||||||||||||||||||||||||||||
| 754 | |||||||||||||||||||||||||||||||||||||||||||
| 755 | 8 | ▶ | my ($attribute) = (ref($attribute_proto)||'') eq 'HASH' ? %$attribute_proto : $attribute_proto; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $attribute_proto || ''
MC/DC100%1/1
ref $attribute_proto || ''
ref $attribute_proto
Truth table100%2/2
A
A= ref $attribute_proto
| |||||||||||||||||||||||||||||||||||||||||||
| 756 | 8 | ▶ | my $errors_classes = exists($options->{errors_classes}) ? delete($options->{errors_classes}) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 757 | 0 | ▶ | $options->{class} = join(' ', (grep { defined $_ } $options->{class}, $errors_classes)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$errors_classes and $self->model->can("errors") and $self->model->errors->where($attribute)
$errors_classes and $self->model->can("errors")
MC/DC0%0/3
$errors_classes and $self->model->can("errors") and $self->model->errors->where($attribute)
$errors_classes
$self->model->can("errors")
$self->model->errors->where($attribute)
Truth table25%1/4
A and B and C
A= $errors_classesB= $self->model->can("errors")C= $self->model->errors->where($attribute)
| |||||||||||||||||||||||||||||||||||||||||||
| 758 | if $errors_classes && $self->model->can('errors') && $self->model->errors->where($attribute); | ||||||||||||||||||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||||||||||||||||
| 760 | 8 | ▶ | my $model = $self->model->can('to_model') ? $self->model->to_model : $self->model; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 761 | 8 | ▶ | my $include_hidden = exists($options->{include_hidden}) ? $options->{include_hidden} : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 762 | 8 | ▶ | my $unselected_default = exists($options->{unselected_value}) ? delete($options->{unselected_value}) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||||||||||||||||
| 764 | |||||||||||||||||||||||||||||||||||||||||||
| 765 | 8 | my @selected = (); | |||||||||||||||||||||||||||||||||||||||||
| 766 | 8 | my $name = ''; | |||||||||||||||||||||||||||||||||||||||||
| 767 | 8 | ▶ | if( (ref($attribute_proto)||'') eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $attribute_proto || ''
MC/DC100%1/1
ref $attribute_proto || ''
ref $attribute_proto
Truth table100%2/2
A
A= ref $attribute_proto
| |||||||||||||||||||||||||||||||||||||||||||
| 768 | 1 | ▶ | $options->{multiple} = 1 unless exists($options->{multiple}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 769 | 1 | $options->{include_hidden} = 0; # Avoid adding two | |||||||||||||||||||||||||||||||||||||||||
| 770 | 1 | my ($bridge, $value_method) = %$attribute_proto; | |||||||||||||||||||||||||||||||||||||||||
| 771 | 1 | my $collection = $model->$bridge; | |||||||||||||||||||||||||||||||||||||||||
| 772 | 1 | ▶ | $collection = $self->tag_helpers->array_to_collection(map { $_->can('to_model') ? $_->to_model : $_ } @$collection) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%1/2
ref $collection || ''
MC/DC0%0/1
ref $collection || ''
ref $collection
Truth table50%1/2
A
A= ref $collection
| |||||||||||||||||||||||||||||||||||||||||||
| 773 | if (ref($collection)||'') eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||||||||||||||||
| 775 | 1 | ▶ | while(my $item = $collection->next) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 776 | 2 | push @selected, $item->$value_method; | |||||||||||||||||||||||||||||||||||||||||
| 777 | } | ||||||||||||||||||||||||||||||||||||||||||
| 778 | 1 | $name = $self->tag_name_for_attribute($bridge, +{multiple=>1}) . ".$value_method"; | |||||||||||||||||||||||||||||||||||||||||
| 779 | 1 | ▶ | $options->{id} = $self->tag_id_for_attribute($bridge) . "_$value_method" unless exists $options->{id}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 780 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 781 | 7 | my $tag_value_proto = $self->tag_value_for_attribute($attribute_proto); | |||||||||||||||||||||||||||||||||||||||||
| 782 | 7 | ▶ | if( (ref($tag_value_proto)||'') eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $tag_value_proto || ''
MC/DC100%1/1
ref $tag_value_proto || ''
ref $tag_value_proto
Truth table100%2/2
A
A= ref $tag_value_proto
| |||||||||||||||||||||||||||||||||||||||||||
| 783 | 1 | @selected = @$tag_value_proto; | |||||||||||||||||||||||||||||||||||||||||
| 784 | 1 | $options->{multiple} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 785 | 1 | $include_hidden = 1; | |||||||||||||||||||||||||||||||||||||||||
| 786 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 787 | 6 | @selected = ($tag_value_proto); | |||||||||||||||||||||||||||||||||||||||||
| 788 | } | ||||||||||||||||||||||||||||||||||||||||||
| 789 | 7 | $name = $self->tag_name_for_attribute($attribute_proto); | |||||||||||||||||||||||||||||||||||||||||
| 790 | 7 | $options->{id} = $self->tag_id_for_attribute($attribute_proto); | |||||||||||||||||||||||||||||||||||||||||
| 791 | } | ||||||||||||||||||||||||||||||||||||||||||
| 792 | |||||||||||||||||||||||||||||||||||||||||||
| 793 | 8 | my $options_tags = ''; | |||||||||||||||||||||||||||||||||||||||||
| 794 | 8 | ▶ | if(!$block) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 795 | 6 | ▶ | my $option_tags_proto = @_ ? shift : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||||||||||||||||
| 797 | # if $option_tags_proto is a string then we assume it is a method name on the model | ||||||||||||||||||||||||||||||||||||||||||
| 798 | 6 | ▶ | if((ref(\$option_tags_proto)||'') eq 'SCALAR') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
ref \$option_tags_proto || ''
MC/DC0%0/1
ref \$option_tags_proto || ''
ref \$option_tags_proto
Truth table50%1/2
A
A= ref \$option_tags_proto
| |||||||||||||||||||||||||||||||||||||||||||
| 799 | 0 | $option_tags_proto = $model->$option_tags_proto; | |||||||||||||||||||||||||||||||||||||||||
| 800 | } | ||||||||||||||||||||||||||||||||||||||||||
| 801 | # if $option_tags_proto is an array ref, where each element is a string | ||||||||||||||||||||||||||||||||||||||||||
| 802 | # then we assume it is a list of values to use for the options | ||||||||||||||||||||||||||||||||||||||||||
| 803 | 6 | ▶ | if((ref($option_tags_proto)||'') eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
ref $option_tags_proto || ''
MC/DC0%0/1
ref $option_tags_proto || ''
ref $option_tags_proto
Truth table50%1/2
A
A= ref $option_tags_proto
| |||||||||||||||||||||||||||||||||||||||||||
| 804 | $option_tags_proto = [ | ||||||||||||||||||||||||||||||||||||||||||
| 805 | map { | ||||||||||||||||||||||||||||||||||||||||||
| 806 | 6 | ▶ | ((ref(\$_)||"") eq 'SCALAR') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
ref \$_ || ''
MC/DC0%0/1
ref \$_ || ''
ref \$_
Truth table50%1/2
A
A= ref \$_
| |||||||||||||||||||||||||||||||||||||||||||
| 807 | ? [$self->human_name_for_label($_), $_] | ||||||||||||||||||||||||||||||||||||||||||
| 808 | : $_; | ||||||||||||||||||||||||||||||||||||||||||
| 809 | } @$option_tags_proto | ||||||||||||||||||||||||||||||||||||||||||
| 810 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 811 | } | ||||||||||||||||||||||||||||||||||||||||||
| 812 | |||||||||||||||||||||||||||||||||||||||||||
| 813 | 6 | ▶ | my @disabled = ( @{delete($options->{disabled})||[]}); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $options->{'disabled'} || []
MC/DC100%1/1
delete $options->{'disabled'} || []
delete $options->{'disabled'}
Truth table100%2/2
A
A= delete $options->{'disabled'}
| |||||||||||||||||||||||||||||||||||||||||||
| 814 | 6 | ▶ | @selected = @{ delete($options->{selected})||[]} if exists($options->{selected}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
delete $options->{'selected'} || []
MC/DC0%0/1
delete $options->{'selected'} || []
delete $options->{'selected'}
Truth table50%1/2
A
A= delete $options->{'selected'}
| |||||||||||||||||||||||||||||||||||||||||||
| 815 | |||||||||||||||||||||||||||||||||||||||||||
| 816 | 0 | ▶ | my @default_selected = @{ delete($options->{default_selected})||[]} if exists($options->{default_selected}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
delete $options->{'default_selected'} || []
MC/DC0%0/1
delete $options->{'default_selected'} || []
delete $options->{'default_selected'}
Truth table0%0/2
A
A= delete $options->{'default_selected'}
| |||||||||||||||||||||||||||||||||||||||||||
| 817 | 6 | ▶ | @selected = @default_selected if @default_selected && !@selected; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@default_selected and not @selected
MC/DC0%0/2
@default_selected and not @selected
@default_selected
not @selected
Truth table33%1/3
A and not(B)
A= @default_selectedB= not @selected
| |||||||||||||||||||||||||||||||||||||||||||
| 818 | |||||||||||||||||||||||||||||||||||||||||||
| 819 | 6 | $options_tags = $self->tag_helpers->options_for_select($option_tags_proto, +{ | |||||||||||||||||||||||||||||||||||||||||
| 820 | selected => \@selected, | ||||||||||||||||||||||||||||||||||||||||||
| 821 | disabled => \@disabled, | ||||||||||||||||||||||||||||||||||||||||||
| 822 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 823 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 824 | 2 | $options_tags = $self->tag_helpers->join_tags($block->($model, $attribute_proto, @selected)); | |||||||||||||||||||||||||||||||||||||||||
| 825 | } | ||||||||||||||||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||||||||||||||||
| 827 | 8 | ▶ | $options->{include_hidden} = 0 if $options->{multiple}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 828 | 8 | my $select_tag = $self->tag_helpers->select_tag($name, $options_tags, $options); | |||||||||||||||||||||||||||||||||||||||||
| 829 | 8 | ▶ | if($include_hidden && $options->{multiple}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$include_hidden and $options->{"multiple"}
MC/DC50%1/2
$include_hidden and $options->{"multiple"}
$include_hidden
$options->{"multiple"}
Truth table66%2/3
A and B
A= $include_hiddenB= $options->{"multiple"}
| |||||||||||||||||||||||||||||||||||||||||||
| 830 | 3 | ▶ | if(ref($attribute_proto)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 831 | 1 | my ($bridge, $value_method) = %$attribute_proto; | |||||||||||||||||||||||||||||||||||||||||
| 832 | 1 | my $hidden = $self->hidden("${bridge}[0]._nop", +{value=>1, id=>$options->{id}.'_hidden'}); | |||||||||||||||||||||||||||||||||||||||||
| 833 | 1 | $select_tag = $self->tag_helpers->join_tags($hidden, $select_tag); | |||||||||||||||||||||||||||||||||||||||||
| 834 | } elsif(defined $unselected_default) { | ||||||||||||||||||||||||||||||||||||||||||
| 835 | 1 | my $hidden = $self->hidden("${attribute_proto}[0]", +{value=>$unselected_default, id=>$options->{id}.'_hidden'}); | |||||||||||||||||||||||||||||||||||||||||
| 836 | 1 | $select_tag = $self->tag_helpers->join_tags($hidden, $select_tag); | |||||||||||||||||||||||||||||||||||||||||
| 837 | } | ||||||||||||||||||||||||||||||||||||||||||
| 838 | } | ||||||||||||||||||||||||||||||||||||||||||
| 839 | 8 | return $select_tag; | |||||||||||||||||||||||||||||||||||||||||
| 840 | } | ||||||||||||||||||||||||||||||||||||||||||
| 841 | |||||||||||||||||||||||||||||||||||||||||||
| 842 | #collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {}) | ||||||||||||||||||||||||||||||||||||||||||
| 843 | 6 | ▶ | sub collection_select { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
collection_select: called CC=41 SCAR=46.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 844 | 6 | my ($self, $method_proto) = (shift, shift); | |||||||||||||||||||||||||||||||||||||||||
| 845 | 6 | ▶ | my $model = $self->model->can('to_model') ? $self->model->to_model : $self->model; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 846 | 6 | ▶ | my $options = (ref($_[-1])||'') eq 'HASH' ? pop(@_) : +{}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $_[-1] || ''
MC/DC100%1/1
ref $_[-1] || ''
ref $_[-1]
Truth table100%2/2
A
A= ref $_[-1]
| |||||||||||||||||||||||||||||||||||||||||||
| 847 | 6 | $options = $self->merge_theme_field_opts('collection_select', undef, $options); | |||||||||||||||||||||||||||||||||||||||||
| 848 | |||||||||||||||||||||||||||||||||||||||||||
| 849 | 6 | my ($collection, $value_method, $label_method) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 850 | |||||||||||||||||||||||||||||||||||||||||||
| 851 | # If the collection of options is not provided then we need to figure out what it is | ||||||||||||||||||||||||||||||||||||||||||
| 852 | 6 | ▶ | if(!defined $collection) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 853 | 0 | my ($options_model, $options_method) = ($model, $method_proto); | |||||||||||||||||||||||||||||||||||||||||
| 854 | 0 | ▶ | if(ref $method_proto) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 855 | 0 | my $bridge; ($bridge, $options_method) = %$method_proto; | |||||||||||||||||||||||||||||||||||||||||
| 856 | 0 | ▶ | if($model->can('related_model')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 857 | 0 | $options_model = $model->related_model($bridge); | |||||||||||||||||||||||||||||||||||||||||
| 858 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 859 | 0 | my $local_model = $model->$bridge; | |||||||||||||||||||||||||||||||||||||||||
| 860 | 0 | ▶ | if($local_model->can('next')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 861 | 0 | $local_model = $local_model->next; | |||||||||||||||||||||||||||||||||||||||||
| 862 | } | ||||||||||||||||||||||||||||||||||||||||||
| 863 | 0 | $options_model = $local_model; | |||||||||||||||||||||||||||||||||||||||||
| 864 | } | ||||||||||||||||||||||||||||||||||||||||||
| 865 | } | ||||||||||||||||||||||||||||||||||||||||||
| 866 | 0 | ($collection, $label_method, $value_method) = $options_model->select_options_for($options_method, %$options); | |||||||||||||||||||||||||||||||||||||||||
| 867 | } | ||||||||||||||||||||||||||||||||||||||||||
| 868 | 6 | ▶ | $collection = $model->$collection if (ref(\$collection)||'') eq 'SCALAR'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
ref \$collection || ''
MC/DC0%0/1
ref \$collection || ''
ref \$collection
Truth table50%1/2
A
A= ref \$collection
| |||||||||||||||||||||||||||||||||||||||||||
| 869 | 6 | ▶ | $value_method = 'value' unless defined($value_method); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 870 | 6 | ▶ | $label_method = 'label' unless defined($label_method); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 871 | |||||||||||||||||||||||||||||||||||||||||||
| 872 | 6 | ▶ | $collection = $model->$collection if (ref(\$collection)||'') eq 'SCALAR'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
ref \$collection || ''
MC/DC0%0/1
ref \$collection || ''
ref \$collection
Truth table50%1/2
A
A= ref \$collection
| |||||||||||||||||||||||||||||||||||||||||||
| 873 | |||||||||||||||||||||||||||||||||||||||||||
| 874 | 6 | ▶ | my $include_hidden = exists($options->{include_hidden}) ? delete($options->{include_hidden}) : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 875 | 6 | my (@selected, $name, $id) = (); | |||||||||||||||||||||||||||||||||||||||||
| 876 | 6 | ▶ | if(ref $method_proto) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 877 | 1 | ▶ | $options->{multiple} = 1 unless exists($options->{multiple}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 878 | 1 | ▶ | $options->{include_hidden} = 0 unless exists($options->{include_hidden}); # Avoid adding two | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 879 | 1 | my ($bridge, $value_method) = %$method_proto; | |||||||||||||||||||||||||||||||||||||||||
| 880 | 1 | my $collection = $model->$bridge; | |||||||||||||||||||||||||||||||||||||||||
| 881 | 1 | ▶ | $collection = $self->tag_helpers->array_to_collection(map { $_->can('to_model') ? $_->to_model : $_ } @$collection) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%1/2
ref $collection || ''
MC/DC0%0/1
ref $collection || ''
ref $collection
Truth table50%1/2
A
A= ref $collection
| |||||||||||||||||||||||||||||||||||||||||||
| 882 | if (ref($collection)||'') eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||
| 883 | |||||||||||||||||||||||||||||||||||||||||||
| 884 | 1 | ▶ | while(my $item = $collection->next) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 885 | 2 | push @selected, $item->$value_method; | |||||||||||||||||||||||||||||||||||||||||
| 886 | } | ||||||||||||||||||||||||||||||||||||||||||
| 887 | 1 | $name = $self->tag_name_for_attribute($bridge, +{multiple=>1}) . ".$value_method"; | |||||||||||||||||||||||||||||||||||||||||
| 888 | 1 | ▶ | $options->{id} = $self->tag_id_for_attribute($bridge) . "_$value_method" unless exists $options->{id}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 889 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 890 | 5 | my $value = $self->tag_value_for_attribute($method_proto); | |||||||||||||||||||||||||||||||||||||||||
| 891 | 5 | ▶ | my $errors_classes = exists($options->{errors_classes}) ? delete($options->{errors_classes}) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 892 | 0 | ▶ | $options->{class} = join(' ', (grep { defined $_ } $options->{class}, $errors_classes)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$model->can("errors") and $model->errors->where($method_proto)
MC/DC0%0/2
$model->can("errors") and $model->errors->where($method_proto)
$model->can("errors")
$model->errors->where($method_proto)
Truth table33%1/3
A and B
A= $model->can("errors")B= $model->errors->where($method_proto)
| |||||||||||||||||||||||||||||||||||||||||||
| 893 | if $model->can('errors') && $model->errors->where($method_proto); | ||||||||||||||||||||||||||||||||||||||||||
| 894 | |||||||||||||||||||||||||||||||||||||||||||
| 895 | 5 | ▶ | if((ref($value)||'') eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%1/2
ref $value || ''
MC/DC0%0/1
ref $value || ''
ref $value
Truth table50%1/2
A
A= ref $value
| |||||||||||||||||||||||||||||||||||||||||||
| 896 | 0 | @selected = @$value; | |||||||||||||||||||||||||||||||||||||||||
| 897 | 0 | ▶ | $options->{multiple} = 1 unless exists($options->{multiple}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 898 | } elsif(defined($value)) { | ||||||||||||||||||||||||||||||||||||||||||
| 899 | 4 | @selected = ($value); | |||||||||||||||||||||||||||||||||||||||||
| 900 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 901 | 1 | @selected = (); | |||||||||||||||||||||||||||||||||||||||||
| 902 | } | ||||||||||||||||||||||||||||||||||||||||||
| 903 | |||||||||||||||||||||||||||||||||||||||||||
| 904 | 5 | $name = $self->tag_name_for_attribute($method_proto); | |||||||||||||||||||||||||||||||||||||||||
| 905 | 5 | $options->{id} = $id = $self->tag_id_for_attribute($method_proto); | |||||||||||||||||||||||||||||||||||||||||
| 906 | } | ||||||||||||||||||||||||||||||||||||||||||
| 907 | |||||||||||||||||||||||||||||||||||||||||||
| 908 | 6 | ▶ | $collection = $self->tag_helpers->array_to_collection(@$collection) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
ref $collection || ''
MC/DC0%0/1
ref $collection || ''
ref $collection
Truth table50%1/2
A
A= ref $collection
| |||||||||||||||||||||||||||||||||||||||||||
| 909 | if (ref($collection)||'') eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||
| 910 | |||||||||||||||||||||||||||||||||||||||||||
| 911 | 6 | ▶ | my @disabled = ( @{delete($options->{disabled})||[]}); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $options->{'disabled'} || []
MC/DC100%1/1
delete $options->{'disabled'} || []
delete $options->{'disabled'}
Truth table100%2/2
A
A= delete $options->{'disabled'}
| |||||||||||||||||||||||||||||||||||||||||||
| 912 | 6 | ▶ | @selected = @{ delete($options->{selected})||[]} if exists($options->{selected}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
delete $options->{'selected'} || []
MC/DC0%0/1
delete $options->{'selected'} || []
delete $options->{'selected'}
Truth table50%1/2
A
A= delete $options->{'selected'}
| |||||||||||||||||||||||||||||||||||||||||||
| 913 | |||||||||||||||||||||||||||||||||||||||||||
| 914 | 6 | ▶ | my @default_selected = @{ delete($options->{default_selected})||[]} if exists($options->{default_selected}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
delete $options->{'default_selected'} || []
MC/DC0%0/1
delete $options->{'default_selected'} || []
delete $options->{'default_selected'}
Truth table50%1/2
A
A= delete $options->{'default_selected'}
| |||||||||||||||||||||||||||||||||||||||||||
| 915 | 6 | ▶ | @selected = @default_selected if @default_selected && !@selected; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@default_selected and not @selected
MC/DC100%2/2
@default_selected and not @selected
@default_selected
not @selected
Truth table100%3/3
A and not(B)
A= @default_selectedB= not @selected
| |||||||||||||||||||||||||||||||||||||||||||
| 916 | |||||||||||||||||||||||||||||||||||||||||||
| 917 | 6 | my $select_tag = $self->tag_helpers->select_tag( | |||||||||||||||||||||||||||||||||||||||||
| 918 | $name, | ||||||||||||||||||||||||||||||||||||||||||
| 919 | $self->tag_helpers->options_from_collection_for_select($collection, $value_method, $label_method, +{ | ||||||||||||||||||||||||||||||||||||||||||
| 920 | selected => \@selected, | ||||||||||||||||||||||||||||||||||||||||||
| 921 | disabled => \@disabled, | ||||||||||||||||||||||||||||||||||||||||||
| 922 | }), | ||||||||||||||||||||||||||||||||||||||||||
| 923 | $options); | ||||||||||||||||||||||||||||||||||||||||||
| 924 | |||||||||||||||||||||||||||||||||||||||||||
| 925 | 6 | ▶ | if($include_hidden && ref($method_proto)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$include_hidden and ref $method_proto
MC/DC50%1/2
$include_hidden and ref $method_proto
$include_hidden
ref $method_proto
Truth table66%2/3
A and B
A= $include_hiddenB= ref $method_proto
| |||||||||||||||||||||||||||||||||||||||||||
| 926 | 1 | my ($bridge, $value_method) = %$method_proto; | |||||||||||||||||||||||||||||||||||||||||
| 927 | 1 | my $hidden = $self->hidden("${bridge}[0]._nop", +{value=>1, id=>$options->{id}.'_hidden'}); | |||||||||||||||||||||||||||||||||||||||||
| 928 | 1 | $select_tag = $self->tag_helpers->join_tags($hidden, $select_tag); | |||||||||||||||||||||||||||||||||||||||||
| 929 | } | ||||||||||||||||||||||||||||||||||||||||||
| 930 | |||||||||||||||||||||||||||||||||||||||||||
| 931 | 6 | return $select_tag; | |||||||||||||||||||||||||||||||||||||||||
| 932 | } | ||||||||||||||||||||||||||||||||||||||||||
| 933 | |||||||||||||||||||||||||||||||||||||||||||
| 934 | 4 | ▶ | sub default_collection_checkbox_include_hidden { return 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_collection_checkbox_include_hidden: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 935 | |||||||||||||||||||||||||||||||||||||||||||
| 936 | # $fb->collection_checkbox({person_roles => role_id}, $roles_rs, $value_method, $text_method, \%options, \&block); | ||||||||||||||||||||||||||||||||||||||||||
| 937 | # $fb->collection_checkbox({person_roles => role_id}, $roles_rs, $value_method, $text_method, \%options, \&block); | ||||||||||||||||||||||||||||||||||||||||||
| 938 | 5 | ▶ | sub collection_checkbox { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
collection_checkbox: called CC=46 SCAR=47.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 939 | 5 | my ($self, $attribute_spec) = (shift, shift); | |||||||||||||||||||||||||||||||||||||||||
| 940 | 5 | ▶ | my $codeblock = (ref($_[-1])||'') eq 'CODE' ? pop(@_) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $_[-1] || ''
MC/DC100%1/1
ref $_[-1] || ''
ref $_[-1]
Truth table100%2/2
A
A= ref $_[-1]
| |||||||||||||||||||||||||||||||||||||||||||
| 941 | 5 | ▶ | my $options = (ref($_[-1])||'') eq 'HASH' ? pop(@_) : +{}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $_[-1] || ''
MC/DC100%1/1
ref $_[-1] || ''
ref $_[-1]
Truth table100%2/2
A
A= ref $_[-1]
| |||||||||||||||||||||||||||||||||||||||||||
| 942 | 5 | $options = $self->merge_theme_field_opts('collection_checkbox', undef, $options); | |||||||||||||||||||||||||||||||||||||||||
| 943 | 5 | ▶ | my $model = $self->model->can('to_model') ? $self->model->to_model : $self->model; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 944 | |||||||||||||||||||||||||||||||||||||||||||
| 945 | 5 | my ($collection, $value_method, $label_method) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 946 | 5 | ▶ | if(!defined $collection) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 947 | 0 | ▶ | if(ref $attribute_spec) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 948 | 0 | my ($bridge, $method) = %$attribute_spec; | |||||||||||||||||||||||||||||||||||||||||
| 949 | 0 | ▶ | if($model->can('related_model')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 950 | 0 | ($collection, $label_method, $value_method) = $model->related_model($bridge)->checkbox_rs_for($method, %$options); | |||||||||||||||||||||||||||||||||||||||||
| 951 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 952 | 0 | my $local_model = $model->$bridge; | |||||||||||||||||||||||||||||||||||||||||
| 953 | 0 | ▶ | if($local_model->can('next')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 954 | 0 | $local_model = $local_model->next; | |||||||||||||||||||||||||||||||||||||||||
| 955 | } | ||||||||||||||||||||||||||||||||||||||||||
| 956 | 0 | ($collection, $label_method, $value_method) = $local_model->checkbox_rs_for($method, %$options); | |||||||||||||||||||||||||||||||||||||||||
| 957 | } | ||||||||||||||||||||||||||||||||||||||||||
| 958 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 959 | 0 | ($collection, $label_method, $value_method) = $model->checkbox_rs_for($attribute_spec, %$options); | |||||||||||||||||||||||||||||||||||||||||
| 960 | } | ||||||||||||||||||||||||||||||||||||||||||
| 961 | } | ||||||||||||||||||||||||||||||||||||||||||
| 962 | |||||||||||||||||||||||||||||||||||||||||||
| 963 | 5 | ▶ | $collection = $model->$collection if (ref(\$collection)||'') eq 'SCALAR'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
ref \$collection || ''
MC/DC0%0/1
ref \$collection || ''
ref \$collection
Truth table50%1/2
A
A= ref \$collection
| |||||||||||||||||||||||||||||||||||||||||||
| 964 | 5 | ▶ | $value_method = 'value' unless defined($value_method); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 965 | 5 | ▶ | $label_method = 'label' unless defined($label_method); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 966 | |||||||||||||||||||||||||||||||||||||||||||
| 967 | 5 | ▶ | my $include_hidden = exists($options->{include_hidden}) ? delete($options->{include_hidden}) : $self->default_collection_checkbox_include_hidden; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 968 | 5 | ▶ | my $container_tag = exists($options->{container_tag}) ? delete($options->{container_tag}) : 'div'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 969 | |||||||||||||||||||||||||||||||||||||||||||
| 970 | # It's either +{ person_roles => role_id } or roles | ||||||||||||||||||||||||||||||||||||||||||
| 971 | 5 | my ($attribute, $attribute_value_method, $is_spec_attribute) = (); | |||||||||||||||||||||||||||||||||||||||||
| 972 | 5 | ▶ | if( (ref($attribute_spec)||'') eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $attribute_spec || ''
MC/DC100%1/1
ref $attribute_spec || ''
ref $attribute_spec
Truth table100%2/2
A
A= ref $attribute_spec
| |||||||||||||||||||||||||||||||||||||||||||
| 973 | 4 | ($attribute, $attribute_value_method) = (%{ $attribute_spec }); | |||||||||||||||||||||||||||||||||||||||||
| 974 | 4 | $is_spec_attribute = 1; | |||||||||||||||||||||||||||||||||||||||||
| 975 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 976 | 1 | $attribute = $attribute_spec; | |||||||||||||||||||||||||||||||||||||||||
| 977 | 1 | $attribute_value_method = $value_method; | |||||||||||||||||||||||||||||||||||||||||
| 978 | } | ||||||||||||||||||||||||||||||||||||||||||
| 979 | |||||||||||||||||||||||||||||||||||||||||||
| 980 | 5 | ▶ | $codeblock = $self->_default_collection_checkbox_content unless defined($codeblock); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 981 | |||||||||||||||||||||||||||||||||||||||||||
| 982 | 5 | my @checked_values = (); | |||||||||||||||||||||||||||||||||||||||||
| 983 | 5 | my $value_collection = $self->tag_value_for_attribute($attribute); | |||||||||||||||||||||||||||||||||||||||||
| 984 | 5 | ▶ | $value_collection = $self->tag_helpers->array_to_collection(map { Scalar::Util::blessed($_) && $_->can('to_model') ? $_->to_model : $_ } @$value_collection) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition60%3/5
ref $value_collection || ''
builtin::blessed($_) and $_->can("to_model")
MC/DC0%0/1
ref $value_collection || ''
ref $value_collection
MC/DC0%0/2
builtin::blessed($_) and $_->can("to_model")
builtin::blessed($_)
$_->can("to_model")
Truth table50%1/2
A
A= ref $value_collection
Truth table66%2/3
A and B
A= builtin::blessed($_)B= $_->can("to_model")
| |||||||||||||||||||||||||||||||||||||||||||
| 985 | if (ref($value_collection)||'') eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||
| 986 | |||||||||||||||||||||||||||||||||||||||||||
| 987 | 5 | ▶ | while(my $value_model = $value_collection->next) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 988 | 10 | ▶ | if($value_model->can($attribute_value_method)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 989 | 8 | ▶ | push @checked_values, $value_model->$attribute_value_method | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$value_model->can("is_marked_for_deletion") and $value_model->is_marked_for_deletion
MC/DC0%0/2
$value_model->can("is_marked_for_deletion") and $value_model->is_marked_for_deletion
$value_model->can("is_marked_for_deletion")
$value_model->is_marked_for_deletion
Truth table33%1/3
A and B
A= $value_model->can("is_marked_for_deletion")B= $value_model->is_marked_for_deletion
| |||||||||||||||||||||||||||||||||||||||||||
| 990 | unless $value_model->can('is_marked_for_deletion') && $value_model->is_marked_for_deletion; | ||||||||||||||||||||||||||||||||||||||||||
| 991 | ▶ | } elsif($value_model->isa('Valiant::HTML::Util::Collection::Item') && $value_model->can('value')) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$value_model->isa("Valiant::HTML::Util::Collection::Item") and $value_model->can("value")
MC/DC0%0/2
$value_model->isa("Valiant::HTML::Util::Collection::Item") and $value_model->can("value")
$value_model->isa("Valiant::HTML::Util::Collection::Item")
$value_model->can("value")
Truth table33%1/3
A and B
A= $value_model->isa("Valiant::HTML::Util::Collection::Item")B= $value_model->can("value")
| |||||||||||||||||||||||||||||||||||||||||||
| 992 | 2 | ▶ | push @checked_values, $value_model->value | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$value_model->can("is_marked_for_deletion") and $value_model->is_marked_for_deletion
MC/DC0%0/2
$value_model->can("is_marked_for_deletion") and $value_model->is_marked_for_deletion
$value_model->can("is_marked_for_deletion")
$value_model->is_marked_for_deletion
Truth table33%1/3
A and B
A= $value_model->can("is_marked_for_deletion")B= $value_model->is_marked_for_deletion
| |||||||||||||||||||||||||||||||||||||||||||
| 993 | unless $value_model->can('is_marked_for_deletion') && $value_model->is_marked_for_deletion; | ||||||||||||||||||||||||||||||||||||||||||
| 994 | }else { | ||||||||||||||||||||||||||||||||||||||||||
| 995 | 0 | warn "Can't find value for " . ref($value_model) . " for $attribute"; | |||||||||||||||||||||||||||||||||||||||||
| 996 | } | ||||||||||||||||||||||||||||||||||||||||||
| 997 | } | ||||||||||||||||||||||||||||||||||||||||||
| 998 | |||||||||||||||||||||||||||||||||||||||||||
| 999 | 5 | my @checkboxes = (); | |||||||||||||||||||||||||||||||||||||||||
| 1000 | my $checkbox_builder_options = +{ | ||||||||||||||||||||||||||||||||||||||||||
| 1001 | 5 | ▶ | builder => (exists($options->{builder}) ? delete($options->{builder}) : $self->DEFAULT_COLLECTION_CHECKBOX_BUILDER), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1002 | value_method => $value_method, | ||||||||||||||||||||||||||||||||||||||||||
| 1003 | label_method => $label_method, | ||||||||||||||||||||||||||||||||||||||||||
| 1004 | attribute_value_method => $attribute_value_method, | ||||||||||||||||||||||||||||||||||||||||||
| 1005 | parent_builder => $self, | ||||||||||||||||||||||||||||||||||||||||||
| 1006 | attribute => $attribute, | ||||||||||||||||||||||||||||||||||||||||||
| 1007 | tag_helpers => $self->tag_helpers, | ||||||||||||||||||||||||||||||||||||||||||
| 1008 | is_spec_attribute => $is_spec_attribute, | ||||||||||||||||||||||||||||||||||||||||||
| 1009 | errors => [$model->errors->where($attribute)], | ||||||||||||||||||||||||||||||||||||||||||
| 1010 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1011 | 5 | ▶ | $checkbox_builder_options->{namespace} = $self->namespace if $self->has_namespace; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1012 | |||||||||||||||||||||||||||||||||||||||||||
| 1013 | 5 | ▶ | $collection = $model->$collection if (ref(\$collection)||'') eq 'SCALAR'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
ref \$collection || ''
MC/DC0%0/1
ref \$collection || ''
ref \$collection
Truth table50%1/2
A
A= ref \$collection
| |||||||||||||||||||||||||||||||||||||||||||
| 1014 | 5 | ▶ | $collection = $self->tag_helpers->array_to_collection(@$collection) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
ref $collection || ''
MC/DC0%0/1
ref $collection || ''
ref $collection
Truth table50%1/2
A
A= ref $collection
| |||||||||||||||||||||||||||||||||||||||||||
| 1015 | if (ref($collection)||'') eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||
| 1016 | |||||||||||||||||||||||||||||||||||||||||||
| 1017 | |||||||||||||||||||||||||||||||||||||||||||
| 1018 | 5 | ▶ | while (my $checkbox_model = $collection->next) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1019 | #my $index = $self->nested_child_index($attribute); | ||||||||||||||||||||||||||||||||||||||||||
| 1020 | 15 | my $name = "@{[ $self->name ]}.${attribute}"; | |||||||||||||||||||||||||||||||||||||||||
| 1021 | my $checked = grep { | ||||||||||||||||||||||||||||||||||||||||||
| 1022 | 15 | ▶ | my $current_value = $checkbox_model->can('read_attribute_for_html') ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1023 | $checkbox_model->read_attribute_for_html($value_method) | ||||||||||||||||||||||||||||||||||||||||||
| 1024 | : $checkbox_model->$value_method; | ||||||||||||||||||||||||||||||||||||||||||
| 1025 | 30 | $_ eq $current_value; | |||||||||||||||||||||||||||||||||||||||||
| 1026 | } @checked_values; | ||||||||||||||||||||||||||||||||||||||||||
| 1027 | |||||||||||||||||||||||||||||||||||||||||||
| 1028 | 15 | ▶ | if($include_hidden && !scalar(@checkboxes)) { # Add nop as first to handle empty list | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$include_hidden and not scalar @checkboxes
MC/DC100%2/2
$include_hidden and not scalar @checkboxes
$include_hidden
not scalar @checkboxes
Truth table100%3/3
A and not(B)
A= $include_hiddenB= not scalar @checkboxes
| |||||||||||||||||||||||||||||||||||||||||||
| 1029 | 4 | my $hidden_fb = $self->tag_helpers->_instantiate_builder($name, $value_collection->build, {%$checkbox_builder_options}); | |||||||||||||||||||||||||||||||||||||||||
| 1030 | 4 | my $hidden_value = $self->_collection_checkbox_hidden_value($attribute, $is_spec_attribute, $options); | |||||||||||||||||||||||||||||||||||||||||
| 1031 | 4 | push @checkboxes, $hidden_fb->hidden($name, +{name=>$name, id=>$self->tag_id_for_attribute($attribute).'_hidden', value=>$hidden_value}); | |||||||||||||||||||||||||||||||||||||||||
| 1032 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1033 | |||||||||||||||||||||||||||||||||||||||||||
| 1034 | #$checkbox_builder_options->{index} = $index; | ||||||||||||||||||||||||||||||||||||||||||
| 1035 | 15 | $checkbox_builder_options->{checked} = $checked; | |||||||||||||||||||||||||||||||||||||||||
| 1036 | 15 | $checkbox_builder_options->{parent_builder} = $self; | |||||||||||||||||||||||||||||||||||||||||
| 1037 | 15 | my $checkbox_fb = $self->tag_helpers->_instantiate_builder($name, $checkbox_model, $checkbox_builder_options); | |||||||||||||||||||||||||||||||||||||||||
| 1038 | 15 | push @checkboxes, $codeblock->($checkbox_fb); | |||||||||||||||||||||||||||||||||||||||||
| 1039 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1040 | 5 | ▶ | $collection->reset if $collection->can('reset'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1041 | 5 | my $checkbox_content = $self->view->safe_concat(@checkboxes); | |||||||||||||||||||||||||||||||||||||||||
| 1042 | |||||||||||||||||||||||||||||||||||||||||||
| 1043 | 5 | ▶ | my $errors_classes = exists($options->{errors_classes}) ? delete($options->{errors_classes}) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1044 | 0 | ▶ | $options->{class} = join(' ', (grep { defined $_ } $options->{class}, $errors_classes)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$errors_classes and $model->can("errors") and $model->errors->where($attribute)
$errors_classes and $model->can("errors")
MC/DC0%0/3
$errors_classes and $model->can("errors") and $model->errors->where($attribute)
$errors_classes
$model->can("errors")
$model->errors->where($attribute)
Truth table25%1/4
A and B and C
A= $errors_classesB= $model->can("errors")C= $model->errors->where($attribute)
| |||||||||||||||||||||||||||||||||||||||||||
| 1045 | if $errors_classes && $model->can('errors') && $model->errors->where($attribute); | ||||||||||||||||||||||||||||||||||||||||||
| 1046 | |||||||||||||||||||||||||||||||||||||||||||
| 1047 | 5 | return $self->tag_helpers->content_tag($container_tag, $checkbox_content, +{ | |||||||||||||||||||||||||||||||||||||||||
| 1048 | id => $self->tag_id_for_attribute($attribute), | ||||||||||||||||||||||||||||||||||||||||||
| 1049 | %$options, | ||||||||||||||||||||||||||||||||||||||||||
| 1050 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 1051 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1052 | |||||||||||||||||||||||||||||||||||||||||||
| 1053 | 4 | ▶ | sub _collection_checkbox_hidden_value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_collection_checkbox_hidden_value: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1054 | 4 | my ($self, $attribute, $is_spec_attribute, $options) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1055 | 4 | ▶ | my $value = $is_spec_attribute ? '{"_nop":""}' : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1056 | 4 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 1057 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1058 | |||||||||||||||||||||||||||||||||||||||||||
| 1059 | 4 | ▶ | sub _default_collection_checkbox_content { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_default_collection_checkbox_content: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1060 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1061 | 12 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1062 | 12 | my ($fb) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1063 | 12 | my $label = $fb->label; | |||||||||||||||||||||||||||||||||||||||||
| 1064 | 12 | my $checkbox = $fb->checkbox; | |||||||||||||||||||||||||||||||||||||||||
| 1065 | 12 | return $self->tag_helpers->join_tags($label, $checkbox); | |||||||||||||||||||||||||||||||||||||||||
| 1066 | 4 | }; | |||||||||||||||||||||||||||||||||||||||||
| 1067 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1068 | |||||||||||||||||||||||||||||||||||||||||||
| 1069 | 2 | ▶ | sub default_collection_radio_buttons_include_hidden { return 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_collection_radio_buttons_include_hidden: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1070 | |||||||||||||||||||||||||||||||||||||||||||
| 1071 | 3 | ▶ | sub collection_radio_buttons { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
collection_radio_buttons: called CC=31 SCAR=41.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1072 | 3 | my ($self, $attribute) = (shift, shift); | |||||||||||||||||||||||||||||||||||||||||
| 1073 | 3 | ▶ | my $codeblock = (ref($_[-1])||'') eq 'CODE' ? pop(@_) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $_[-1] || ''
MC/DC100%1/1
ref $_[-1] || ''
ref $_[-1]
Truth table100%2/2
A
A= ref $_[-1]
| |||||||||||||||||||||||||||||||||||||||||||
| 1074 | 3 | ▶ | my $options = (ref($_[-1])||'') eq 'HASH' ? pop(@_) : +{}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $_[-1] || ''
MC/DC100%1/1
ref $_[-1] || ''
ref $_[-1]
Truth table100%2/2
A
A= ref $_[-1]
| |||||||||||||||||||||||||||||||||||||||||||
| 1075 | 3 | $options = $self->merge_theme_field_opts('collection_radio_buttons', $attribute, $options); | |||||||||||||||||||||||||||||||||||||||||
| 1076 | |||||||||||||||||||||||||||||||||||||||||||
| 1077 | 3 | ▶ | my $model = $self->model->can('to_model') ? $self->model->to_model : $self->model; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1078 | |||||||||||||||||||||||||||||||||||||||||||
| 1079 | 3 | my ($collection, $value_method, $label_method) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1080 | 3 | ▶ | if(!defined $collection) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1081 | 0 | ▶ | if(ref $attribute) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1082 | 0 | my ($bridge, $method) = %$attribute; | |||||||||||||||||||||||||||||||||||||||||
| 1083 | 0 | ▶ | if($model->can('related_model')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1084 | 0 | ($collection, $label_method, $value_method) = $model->related_model($bridge)->radio_button_rs_for($method, %$options); | |||||||||||||||||||||||||||||||||||||||||
| 1085 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1086 | 0 | my $local_model = $model->$bridge; | |||||||||||||||||||||||||||||||||||||||||
| 1087 | 0 | ▶ | if($local_model->can('next')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1088 | 0 | $local_model = $local_model->next; | |||||||||||||||||||||||||||||||||||||||||
| 1089 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1090 | 0 | ($collection, $label_method, $value_method) = $local_model->radio_button_rs_for($method, %$options); | |||||||||||||||||||||||||||||||||||||||||
| 1091 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1092 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1093 | 0 | ($collection, $label_method, $value_method) = $model->radio_button_rs_for($attribute, %$options); | |||||||||||||||||||||||||||||||||||||||||
| 1094 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1095 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1096 | 3 | ▶ | $value_method = 'value' unless defined($value_method); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1097 | 3 | ▶ | $label_method = 'label' unless defined($label_method); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1098 | |||||||||||||||||||||||||||||||||||||||||||
| 1099 | 3 | ▶ | my $checked_value = exists($options->{checked_value}) ? delete($options->{checked_value}) : $self->tag_value_for_attribute($attribute); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1100 | 3 | ▶ | my $include_hidden = exists($options->{include_hidden}) ? delete($options->{include_hidden}) : $self->default_collection_radio_buttons_include_hidden; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1101 | 3 | ▶ | my $container_tag = exists($options->{container_tag}) ? delete($options->{container_tag}) : 'div'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1102 | |||||||||||||||||||||||||||||||||||||||||||
| 1103 | 3 | ▶ | $codeblock = $self->_default_collection_radio_buttons_content unless defined($codeblock); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1104 | |||||||||||||||||||||||||||||||||||||||||||
| 1105 | 3 | my @radio_buttons = (); | |||||||||||||||||||||||||||||||||||||||||
| 1106 | my $radio_buttons_builder_options = +{ | ||||||||||||||||||||||||||||||||||||||||||
| 1107 | 3 | ▶ | builder => (exists($options->{builder}) ? delete($options->{builder}) : $self->DEFAULT_COLLECTION_RADIO_BUTTON_BUILDER), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1108 | value_method => $value_method, | ||||||||||||||||||||||||||||||||||||||||||
| 1109 | label_method => $label_method, | ||||||||||||||||||||||||||||||||||||||||||
| 1110 | checked_value => $checked_value, | ||||||||||||||||||||||||||||||||||||||||||
| 1111 | parent_builder => $self, | ||||||||||||||||||||||||||||||||||||||||||
| 1112 | attribute => $attribute, | ||||||||||||||||||||||||||||||||||||||||||
| 1113 | tag_helpers => $self->tag_helpers, | ||||||||||||||||||||||||||||||||||||||||||
| 1114 | errors => [$model->errors->where($attribute)], | ||||||||||||||||||||||||||||||||||||||||||
| 1115 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1116 | 3 | ▶ | $radio_buttons_builder_options->{namespace} = $self->namespace if $self->has_namespace; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1117 | |||||||||||||||||||||||||||||||||||||||||||
| 1118 | 3 | ▶ | $collection = $model->$collection if (ref(\$collection)||'') eq 'SCALAR'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
ref \$collection || ''
MC/DC0%0/1
ref \$collection || ''
ref \$collection
Truth table50%1/2
A
A= ref \$collection
| |||||||||||||||||||||||||||||||||||||||||||
| 1119 | 3 | ▶ | while (my $radio_button_model = $collection->next) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1120 | 9 | my $name = "@{[ $self->name ]}.${attribute}"; | |||||||||||||||||||||||||||||||||||||||||
| 1121 | 9 | ▶ | my $current_value = $radio_button_model->can('read_attribute_for_html') ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1122 | $radio_button_model->read_attribute_for_html($value_method) : | ||||||||||||||||||||||||||||||||||||||||||
| 1123 | $radio_button_model->$value_method; | ||||||||||||||||||||||||||||||||||||||||||
| 1124 | 9 | ▶ | my $checked = $current_value eq ($checked_value||'') ? 1:0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$checked_value || ''
MC/DC0%0/1
$checked_value || ''
$checked_value
Truth table50%1/2
A
A= $checked_value
| |||||||||||||||||||||||||||||||||||||||||||
| 1125 | |||||||||||||||||||||||||||||||||||||||||||
| 1126 | 9 | ▶ | if($include_hidden && !scalar(@radio_buttons) ) { # Add nop as first to handle empty list | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$include_hidden and not scalar @radio_buttons
MC/DC100%2/2
$include_hidden and not scalar @radio_buttons
$include_hidden
not scalar @radio_buttons
Truth table100%3/3
A and not(B)
A= $include_hiddenB= not scalar @radio_buttons
| |||||||||||||||||||||||||||||||||||||||||||
| 1127 | 2 | my $hidden_fb = $self->tag_helpers->_instantiate_builder($name, $model, $radio_buttons_builder_options); | |||||||||||||||||||||||||||||||||||||||||
| 1128 | 2 | push @radio_buttons, $hidden_fb->hidden($name, +{name=>$name, id=>$self->tag_id_for_attribute($attribute).'_hidden', value=>''}); | |||||||||||||||||||||||||||||||||||||||||
| 1129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1130 | |||||||||||||||||||||||||||||||||||||||||||
| 1131 | 9 | $radio_buttons_builder_options->{checked} = $checked; | |||||||||||||||||||||||||||||||||||||||||
| 1132 | |||||||||||||||||||||||||||||||||||||||||||
| 1133 | 9 | my $radio_button_fb = $self->tag_helpers->_instantiate_builder($name, $radio_button_model, $radio_buttons_builder_options); | |||||||||||||||||||||||||||||||||||||||||
| 1134 | 9 | push @radio_buttons, $codeblock->($radio_button_fb); | |||||||||||||||||||||||||||||||||||||||||
| 1135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1136 | 3 | ▶ | $collection->reset if $collection->can('reset'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1137 | 3 | my $radios = $self->view->safe_concat(@radio_buttons); | |||||||||||||||||||||||||||||||||||||||||
| 1138 | |||||||||||||||||||||||||||||||||||||||||||
| 1139 | 3 | ▶ | my $errors_classes = exists($options->{errors_classes}) ? delete($options->{errors_classes}) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1140 | 0 | ▶ | $options->{class} = join(' ', (grep { defined $_ } $options->{class}, $errors_classes)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$errors_classes and $model->can("errors") and $model->errors->where($attribute)
$errors_classes and $model->can("errors")
MC/DC0%0/3
$errors_classes and $model->can("errors") and $model->errors->where($attribute)
$errors_classes
$model->can("errors")
$model->errors->where($attribute)
Truth table25%1/4
A and B and C
A= $errors_classesB= $model->can("errors")C= $model->errors->where($attribute)
| |||||||||||||||||||||||||||||||||||||||||||
| 1141 | if $errors_classes && $model->can('errors') && $model->errors->where($attribute); | ||||||||||||||||||||||||||||||||||||||||||
| 1142 | |||||||||||||||||||||||||||||||||||||||||||
| 1143 | 3 | return $self->tag_helpers->content_tag($container_tag, $radios, +{ | |||||||||||||||||||||||||||||||||||||||||
| 1144 | id => $self->tag_id_for_attribute($attribute), | ||||||||||||||||||||||||||||||||||||||||||
| 1145 | %$options, | ||||||||||||||||||||||||||||||||||||||||||
| 1146 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 1147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1148 | |||||||||||||||||||||||||||||||||||||||||||
| 1149 | 2 | ▶ | sub _default_collection_radio_buttons_content { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_default_collection_radio_buttons_content: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1150 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1151 | 6 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1152 | 6 | my ($fb) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1153 | 6 | my $label = $fb->label(); | |||||||||||||||||||||||||||||||||||||||||
| 1154 | 6 | my $checkbox = $fb->radio_button(); | |||||||||||||||||||||||||||||||||||||||||
| 1155 | 6 | return $self->tag_helpers->join_tags($label, $checkbox); | |||||||||||||||||||||||||||||||||||||||||
| 1156 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||
| 1157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1158 | |||||||||||||||||||||||||||||||||||||||||||
| 1159 | 0 | ▶ | sub radio_buttons { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
radio_buttons: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1160 | 0 | my ($self, $attribute) = (shift, shift); | |||||||||||||||||||||||||||||||||||||||||
| 1161 | 0 | ▶ | my $model = $self->model->can('to_model') ? $self->model->to_model : $self->model; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1162 | 0 | ▶ | my $codeblock = (ref($_[-1])||'') eq 'CODE' ? pop(@_) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
ref $_[-1] || ''
MC/DC0%0/1
ref $_[-1] || ''
ref $_[-1]
Truth table0%0/2
A
A= ref $_[-1]
| |||||||||||||||||||||||||||||||||||||||||||
| 1163 | 0 | ▶ | my $options = (ref($_[-1])||'') eq 'HASH' ? pop(@_) : +{}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
ref $_[-1] || ''
MC/DC0%0/1
ref $_[-1] || ''
ref $_[-1]
Truth table0%0/2
A
A= ref $_[-1]
| |||||||||||||||||||||||||||||||||||||||||||
| 1164 | 0 | $options = $self->merge_theme_field_opts('radio_buttons', $attribute, $options); | |||||||||||||||||||||||||||||||||||||||||
| 1165 | |||||||||||||||||||||||||||||||||||||||||||
| 1166 | # If args then its either a string to the model method or an arrayref of option | ||||||||||||||||||||||||||||||||||||||||||
| 1167 | 0 | ▶ | if(@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1168 | 0 | my ($collection, $value_method, $label_method) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1169 | 0 | ▶ | $collection = do { my $method = shift; $model->$method } if (ref(\$_[0])||'') eq 'SCALAR'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
ref \$_[0] || ''
MC/DC0%0/1
ref \$_[0] || ''
ref \$_[0]
Truth table0%0/2
A
A= ref \$_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 1170 | 0 | ▶ | $collection = $self->tag_helpers->array_to_collection(@{shift(@_)}) if (ref($_[0])||'') eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
ref $_[0] || ''
MC/DC0%0/1
ref $_[0] || ''
ref $_[0]
Truth table0%0/2
A
A= ref $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 1171 | 0 | ▶ | $value_method = 'value' unless defined($value_method); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1172 | 0 | ▶ | $label_method = 'label' unless defined($label_method); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1173 | 0 | return $self->collection_radio_buttons($attribute, $collection, $value_method, $label_method, $options, $codeblock); | |||||||||||||||||||||||||||||||||||||||||
| 1174 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1175 | # If we are here that means we are using the model method to get the collection | ||||||||||||||||||||||||||||||||||||||||||
| 1176 | 0 | my @buttons = $model->radio_buttons_for($attribute, %$options); | |||||||||||||||||||||||||||||||||||||||||
| 1177 | 0 | my $collection = $self->tag_helpers->array_to_collection(@buttons); | |||||||||||||||||||||||||||||||||||||||||
| 1178 | 0 | my $value_method = 'value'; | |||||||||||||||||||||||||||||||||||||||||
| 1179 | 0 | my $label_method = 'label'; | |||||||||||||||||||||||||||||||||||||||||
| 1180 | 0 | return $self->collection_radio_buttons($attribute, $collection, $value_method, $label_method, $options, $codeblock); | |||||||||||||||||||||||||||||||||||||||||
| 1181 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1183 | |||||||||||||||||||||||||||||||||||||||||||
| 1184 | 7 | ▶ | sub field { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
field: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1185 | 7 | my ($self, $attribute, $cb) = (shift, shift, shift); | |||||||||||||||||||||||||||||||||||||||||
| 1186 | 7 | my $proxy = Valiant::HTML::FormBuilder::Proxy->new( | |||||||||||||||||||||||||||||||||||||||||
| 1187 | form_builder => $self, | ||||||||||||||||||||||||||||||||||||||||||
| 1188 | attribute => $attribute, | ||||||||||||||||||||||||||||||||||||||||||
| 1189 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1190 | 7 | ▶ | return $proxy unless $cb; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1191 | |||||||||||||||||||||||||||||||||||||||||||
| 1192 | my @return = map { | ||||||||||||||||||||||||||||||||||||||||||
| 1193 | 3 | ▶ | Scalar::Util::blessed($_) && $_->can('to_safe_string') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
builtin::blessed($_) and $_->can("to_safe_string")
MC/DC100%2/2
builtin::blessed($_) and $_->can("to_safe_string")
builtin::blessed($_)
$_->can("to_safe_string")
Truth table100%3/3
A and B
A= builtin::blessed($_)B= $_->can("to_safe_string")
| |||||||||||||||||||||||||||||||||||||||||||
| 1194 | ? $_->to_safe_string | ||||||||||||||||||||||||||||||||||||||||||
| 1195 | : $_; | ||||||||||||||||||||||||||||||||||||||||||
| 1196 | } $cb->($proxy); | ||||||||||||||||||||||||||||||||||||||||||
| 1197 | |||||||||||||||||||||||||||||||||||||||||||
| 1198 | 3 | return Valiant::HTML::FormBuilder::Proxy->new( | |||||||||||||||||||||||||||||||||||||||||
| 1199 | form_builder => $self, | ||||||||||||||||||||||||||||||||||||||||||
| 1200 | attribute => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 1201 | _parts => \@return, | ||||||||||||||||||||||||||||||||||||||||||
| 1202 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1203 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1204 | |||||||||||||||||||||||||||||||||||||||||||
| 1205 | package Valiant::HTML::FormBuilder::Proxy; | ||||||||||||||||||||||||||||||||||||||||||
| 1206 | |||||||||||||||||||||||||||||||||||||||||||
| 1207 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1208 | use overload | ||||||||||||||||||||||||||||||||||||||||||
| 1209 | 4 | ▶ | '""' => sub { $_[0]->to_string() }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1210 | 0 | ▶ | '0+' => sub { $_[0]->to_string() }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1211 | 2 | fallback => 1; | |||||||||||||||||||||||||||||||||||||||||
| 1212 | |||||||||||||||||||||||||||||||||||||||||||
| 1213 | 2 | has 'attribute' => (is=>'ro', required=>0); | |||||||||||||||||||||||||||||||||||||||||
| 1214 | 2 | has 'form_builder' => (is=>'ro', required=>1); | |||||||||||||||||||||||||||||||||||||||||
| 1215 | 7 | ▶ | has '_parts' => (is=>'rw', default=>sub { [] }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1216 | |||||||||||||||||||||||||||||||||||||||||||
| 1217 | 15 | ▶ | sub _add_part { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_add_part: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1218 | 15 | my ($self, @new_parts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1219 | 15 | my @parts = @{$self->_parts}; | |||||||||||||||||||||||||||||||||||||||||
| 1220 | 15 | $self->_parts([@parts, @new_parts]); | |||||||||||||||||||||||||||||||||||||||||
| 1221 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1222 | |||||||||||||||||||||||||||||||||||||||||||
| 1223 | 0 | ▶ | sub _clear { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_clear: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1224 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1225 | 0 | $self->_parts([]); | |||||||||||||||||||||||||||||||||||||||||
| 1226 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 1227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1228 | |||||||||||||||||||||||||||||||||||||||||||
| 1229 | 7 | ▶ | sub to_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_string: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1230 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1231 | 7 | ▶ | my @parts = map { ref($_) eq 'CODE' ? $_->() : $_ } @{$self->_parts}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1232 | 7 | return my $safe = $self->form_builder->view->safe_concat(@parts); | |||||||||||||||||||||||||||||||||||||||||
| 1233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1234 | |||||||||||||||||||||||||||||||||||||||||||
| 1235 | # support for Template::EmbeddedPerl safe stringification | ||||||||||||||||||||||||||||||||||||||||||
| 1236 | 3 | ▶ | sub to_safe_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_safe_string: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1237 | 3 | my ($self, $template) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1238 | 3 | return $self->to_string; | |||||||||||||||||||||||||||||||||||||||||
| 1239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1240 | |||||||||||||||||||||||||||||||||||||||||||
| 1241 | 1 | ▶ | sub end { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
end: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1242 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1243 | 1 | my $class = ref $self; | |||||||||||||||||||||||||||||||||||||||||
| 1244 | 1 | return $class->new( | |||||||||||||||||||||||||||||||||||||||||
| 1245 | form_builder => $self->form_builder, | ||||||||||||||||||||||||||||||||||||||||||
| 1246 | attribute => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 1247 | _parts => $self->_parts, | ||||||||||||||||||||||||||||||||||||||||||
| 1248 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1249 | |||||||||||||||||||||||||||||||||||||||||||
| 1250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1251 | |||||||||||||||||||||||||||||||||||||||||||
| 1252 | 29 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1253 | 29 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1254 | 29 | my $method = our $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||
| 1255 | 29 | $method =~ s/.*:://; # remove package name | |||||||||||||||||||||||||||||||||||||||||
| 1256 | |||||||||||||||||||||||||||||||||||||||||||
| 1257 | 29 | ▶ | return if $method eq 'DESTROY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1258 | |||||||||||||||||||||||||||||||||||||||||||
| 1259 | # This really needs to do the right thing and delegate the $method call | ||||||||||||||||||||||||||||||||||||||||||
| 1260 | # based on what $method is. That's why this feature is prototype status | ||||||||||||||||||||||||||||||||||||||||||
| 1261 | # and undocumented! | ||||||||||||||||||||||||||||||||||||||||||
| 1262 | |||||||||||||||||||||||||||||||||||||||||||
| 1263 | 18 | ▶ | if($self->form_builder->can($method)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1264 | 18 | my $fb = $self->form_builder; | |||||||||||||||||||||||||||||||||||||||||
| 1265 | 18 | my $attribute = $self->attribute; | |||||||||||||||||||||||||||||||||||||||||
| 1266 | 18 | ▶ | my @args = $attribute ? ($attribute, @_) : (@_); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1267 | 18 | my $result = $fb->$method(@args); | |||||||||||||||||||||||||||||||||||||||||
| 1268 | |||||||||||||||||||||||||||||||||||||||||||
| 1269 | 18 | ▶ | if(Scalar::Util::blessed($result) && $result->isa('Valiant::HTML::FormBuilder::Proxy')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($result) and $result->isa("Valiant::HTML::FormBuilder::Proxy")
MC/DC50%1/2
builtin::blessed($result) and $result->isa("Valiant::HTML::FormBuilder::Proxy")
builtin::blessed($result)
$result->isa("Valiant::HTML::FormBuilder::Proxy")
Truth table66%2/3
A and B
A= builtin::blessed($result)B= $result->isa("Valiant::HTML::FormBuilder::Proxy")
| |||||||||||||||||||||||||||||||||||||||||||
| 1270 | 3 | $result->_parts([ @{$self->_parts}, @{$result->_parts}]); | |||||||||||||||||||||||||||||||||||||||||
| 1271 | 3 | return $result; | |||||||||||||||||||||||||||||||||||||||||
| 1272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1273 | |||||||||||||||||||||||||||||||||||||||||||
| 1274 | 15 | $self->_add_part($result); | |||||||||||||||||||||||||||||||||||||||||
| 1275 | 15 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 1276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1277 | |||||||||||||||||||||||||||||||||||||||||||
| 1278 | 0 | die "Can't find method $method on " | |||||||||||||||||||||||||||||||||||||||||
| 1279 | . ref($self->form_builder) | ||||||||||||||||||||||||||||||||||||||||||
| 1280 | . " for attribute " | ||||||||||||||||||||||||||||||||||||||||||
| 1281 | . $self->attribute; | ||||||||||||||||||||||||||||||||||||||||||
| 1282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1283 | |||||||||||||||||||||||||||||||||||||||||||
| 1284 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 1285 | |||||||||||||||||||||||||||||||||||||||||||
| 1286 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 1287 | |||||||||||||||||||||||||||||||||||||||||||
| 1288 | Valiant::HTML::FormBuilder - General HTML Forms | ||||||||||||||||||||||||||||||||||||||||||
| 1289 | |||||||||||||||||||||||||||||||||||||||||||
| 1290 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 1291 | |||||||||||||||||||||||||||||||||||||||||||
| 1292 | Given a model with the correct API such as: | ||||||||||||||||||||||||||||||||||||||||||
| 1293 | |||||||||||||||||||||||||||||||||||||||||||
| 1294 | package Local::Person; | ||||||||||||||||||||||||||||||||||||||||||
| 1295 | |||||||||||||||||||||||||||||||||||||||||||
| 1296 | use Moo; | ||||||||||||||||||||||||||||||||||||||||||
| 1297 | use Valiant::Validations; | ||||||||||||||||||||||||||||||||||||||||||
| 1298 | |||||||||||||||||||||||||||||||||||||||||||
| 1299 | has first_name => (is=>'ro'); | ||||||||||||||||||||||||||||||||||||||||||
| 1300 | has last_name => (is=>'ro'); | ||||||||||||||||||||||||||||||||||||||||||
| 1301 | |||||||||||||||||||||||||||||||||||||||||||
| 1302 | validates ['first_name', 'last_name'] => ( | ||||||||||||||||||||||||||||||||||||||||||
| 1303 | length => { | ||||||||||||||||||||||||||||||||||||||||||
| 1304 | maximum => 10, | ||||||||||||||||||||||||||||||||||||||||||
| 1305 | minimum => 3, | ||||||||||||||||||||||||||||||||||||||||||
| 1306 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1307 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1308 | |||||||||||||||||||||||||||||||||||||||||||
| 1309 | Wrap a formbuilder object around it and generate HTML form field controls: | ||||||||||||||||||||||||||||||||||||||||||
| 1310 | |||||||||||||||||||||||||||||||||||||||||||
| 1311 | my $person = Local::Person->new(first_name=>'J', last_name=>'Napiorkowski'); | ||||||||||||||||||||||||||||||||||||||||||
| 1312 | $person->validate; | ||||||||||||||||||||||||||||||||||||||||||
| 1313 | |||||||||||||||||||||||||||||||||||||||||||
| 1314 | my $fb = Valiant::HTML::FormBuilder->new( | ||||||||||||||||||||||||||||||||||||||||||
| 1315 | model => $person, | ||||||||||||||||||||||||||||||||||||||||||
| 1316 | name => 'person' | ||||||||||||||||||||||||||||||||||||||||||
| 1317 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1318 | |||||||||||||||||||||||||||||||||||||||||||
| 1319 | print $fb->input('first_name'); | ||||||||||||||||||||||||||||||||||||||||||
| 1320 | # <input id="person_first_name" name="person.first_name" type="text" value="J"/> | ||||||||||||||||||||||||||||||||||||||||||
| 1321 | |||||||||||||||||||||||||||||||||||||||||||
| 1322 | print $fb->errors_for('first_name'); | ||||||||||||||||||||||||||||||||||||||||||
| 1323 | # <div>First Name is too short (minimum is 3 characters)</div> | ||||||||||||||||||||||||||||||||||||||||||
| 1324 | |||||||||||||||||||||||||||||||||||||||||||
| 1325 | Although you can create a formbuilder instance directly as in the above example you might | ||||||||||||||||||||||||||||||||||||||||||
| 1326 | find it easier to use the helper method L<Valiant::HTML::Util::Form/form_for> which encapsulates | ||||||||||||||||||||||||||||||||||||||||||
| 1327 | the display logic needed for creating the C<form> tags. This builder creates form tag elements | ||||||||||||||||||||||||||||||||||||||||||
| 1328 | but not the actual C<form> open and close tags. | ||||||||||||||||||||||||||||||||||||||||||
| 1329 | |||||||||||||||||||||||||||||||||||||||||||
| 1330 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 1331 | |||||||||||||||||||||||||||||||||||||||||||
| 1332 | This class wraps an underlying data model and makes it easy to build HTML form elements based on | ||||||||||||||||||||||||||||||||||||||||||
| 1333 | the state of that model. Inspiration for this design come from Ruby on Rails Formbuilder as well | ||||||||||||||||||||||||||||||||||||||||||
| 1334 | as similar designs in the Phoenix Framework. | ||||||||||||||||||||||||||||||||||||||||||
| 1335 | |||||||||||||||||||||||||||||||||||||||||||
| 1336 | You can subclass this to future customize how your form elements display as well as to add more complex | ||||||||||||||||||||||||||||||||||||||||||
| 1337 | form elements for your templates. | ||||||||||||||||||||||||||||||||||||||||||
| 1338 | |||||||||||||||||||||||||||||||||||||||||||
| 1339 | Documentation here is basically API level, a more detailed tutorial will follow eventually but for now | ||||||||||||||||||||||||||||||||||||||||||
| 1340 | you'll need to review the source, test cases and example application bundled with this distribution | ||||||||||||||||||||||||||||||||||||||||||
| 1341 | for for hand holding. | ||||||||||||||||||||||||||||||||||||||||||
| 1342 | |||||||||||||||||||||||||||||||||||||||||||
| 1343 | Currently this is designed to work mostly with the L<Valiant> model validation framework as well as the | ||||||||||||||||||||||||||||||||||||||||||
| 1344 | glue for L<DBIx::Class>, L<DBIx::Class::Valiant>, although I did take pains to try and make the API | ||||||||||||||||||||||||||||||||||||||||||
| 1345 | agnostic many of the test cases are assuming that stack and getting that integration working well is | ||||||||||||||||||||||||||||||||||||||||||
| 1346 | the primary use case for me. Thoughts and code to make this more stand alone are very welcomed. | ||||||||||||||||||||||||||||||||||||||||||
| 1347 | |||||||||||||||||||||||||||||||||||||||||||
| 1348 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||||||||||||||||
| 1349 | |||||||||||||||||||||||||||||||||||||||||||
| 1350 | This class defines the following attributes used in creating an instance. | ||||||||||||||||||||||||||||||||||||||||||
| 1351 | |||||||||||||||||||||||||||||||||||||||||||
| 1352 | =head2 model | ||||||||||||||||||||||||||||||||||||||||||
| 1353 | |||||||||||||||||||||||||||||||||||||||||||
| 1354 | This is the data model that the formbuilder inspects for field state and error conditions. This should be | ||||||||||||||||||||||||||||||||||||||||||
| 1355 | a model that does the API described here: L<Valiant::HTML::Util::Form/"REQUIRED MODEL API">. Required but the API | ||||||||||||||||||||||||||||||||||||||||||
| 1356 | is pretty flexible (see docs). | ||||||||||||||||||||||||||||||||||||||||||
| 1357 | |||||||||||||||||||||||||||||||||||||||||||
| 1358 | Please note that my initial use case for this is using L<Valiant> for validation and L<DBIx::Class> as the | ||||||||||||||||||||||||||||||||||||||||||
| 1359 | model (via L<DBIx::Class::Valiant>) so that combination has the most testing and examples. If you are using | ||||||||||||||||||||||||||||||||||||||||||
| 1360 | a different storage or validation setup you need to complete the API described. Please send test cases | ||||||||||||||||||||||||||||||||||||||||||
| 1361 | and pull requests to improve interoperability! | ||||||||||||||||||||||||||||||||||||||||||
| 1362 | |||||||||||||||||||||||||||||||||||||||||||
| 1363 | =head2 name | ||||||||||||||||||||||||||||||||||||||||||
| 1364 | |||||||||||||||||||||||||||||||||||||||||||
| 1365 | This is a string which is the internal name given to the model. This is used to set a namespace for form | ||||||||||||||||||||||||||||||||||||||||||
| 1366 | field C<name> attributes and the default namespace for C<id> attributes. Required. | ||||||||||||||||||||||||||||||||||||||||||
| 1367 | |||||||||||||||||||||||||||||||||||||||||||
| 1368 | =head2 options | ||||||||||||||||||||||||||||||||||||||||||
| 1369 | |||||||||||||||||||||||||||||||||||||||||||
| 1370 | A optional hashref of options used in form field generation. Some of these might become attributes in the | ||||||||||||||||||||||||||||||||||||||||||
| 1371 | future. Here's a list of the current options | ||||||||||||||||||||||||||||||||||||||||||
| 1372 | |||||||||||||||||||||||||||||||||||||||||||
| 1373 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 1374 | |||||||||||||||||||||||||||||||||||||||||||
| 1375 | =item index | ||||||||||||||||||||||||||||||||||||||||||
| 1376 | |||||||||||||||||||||||||||||||||||||||||||
| 1377 | The index of the formbuilder when it is a sub formbuilder with a parent and we are iterating over a collection. | ||||||||||||||||||||||||||||||||||||||||||
| 1378 | |||||||||||||||||||||||||||||||||||||||||||
| 1379 | =item child_index | ||||||||||||||||||||||||||||||||||||||||||
| 1380 | |||||||||||||||||||||||||||||||||||||||||||
| 1381 | When creating a sub formbuilder that is an element in a collection, this is used to pass the index value | ||||||||||||||||||||||||||||||||||||||||||
| 1382 | |||||||||||||||||||||||||||||||||||||||||||
| 1383 | =item builder | ||||||||||||||||||||||||||||||||||||||||||
| 1384 | |||||||||||||||||||||||||||||||||||||||||||
| 1385 | The package name of the current builder | ||||||||||||||||||||||||||||||||||||||||||
| 1386 | |||||||||||||||||||||||||||||||||||||||||||
| 1387 | =item parent_builder | ||||||||||||||||||||||||||||||||||||||||||
| 1388 | |||||||||||||||||||||||||||||||||||||||||||
| 1389 | The parent formbuilder instance to a sub builder. | ||||||||||||||||||||||||||||||||||||||||||
| 1390 | |||||||||||||||||||||||||||||||||||||||||||
| 1391 | =item include_id | ||||||||||||||||||||||||||||||||||||||||||
| 1392 | |||||||||||||||||||||||||||||||||||||||||||
| 1393 | Used to indicated that a sub formbuilder should add hidden fields indicating the storage ID for the current model. | ||||||||||||||||||||||||||||||||||||||||||
| 1394 | |||||||||||||||||||||||||||||||||||||||||||
| 1395 | =item namespace | ||||||||||||||||||||||||||||||||||||||||||
| 1396 | |||||||||||||||||||||||||||||||||||||||||||
| 1397 | The ID namespace; used to populate the C<namespace> attribute. | ||||||||||||||||||||||||||||||||||||||||||
| 1398 | |||||||||||||||||||||||||||||||||||||||||||
| 1399 | =item as | ||||||||||||||||||||||||||||||||||||||||||
| 1400 | |||||||||||||||||||||||||||||||||||||||||||
| 1401 | Used to override how the class and ids are made for your forms. | ||||||||||||||||||||||||||||||||||||||||||
| 1402 | |||||||||||||||||||||||||||||||||||||||||||
| 1403 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 1404 | |||||||||||||||||||||||||||||||||||||||||||
| 1405 | =head2 index | ||||||||||||||||||||||||||||||||||||||||||
| 1406 | |||||||||||||||||||||||||||||||||||||||||||
| 1407 | The current index of a collection for which the current formbuilder is one item in. | ||||||||||||||||||||||||||||||||||||||||||
| 1408 | |||||||||||||||||||||||||||||||||||||||||||
| 1409 | =head2 namespace | ||||||||||||||||||||||||||||||||||||||||||
| 1410 | |||||||||||||||||||||||||||||||||||||||||||
| 1411 | Used to add a prefix to the ID for your form elements. | ||||||||||||||||||||||||||||||||||||||||||
| 1412 | |||||||||||||||||||||||||||||||||||||||||||
| 1413 | =head2 skip_default_ids | ||||||||||||||||||||||||||||||||||||||||||
| 1414 | |||||||||||||||||||||||||||||||||||||||||||
| 1415 | Defaults to false. Generally we create an html C<id> attribute for the field based | ||||||||||||||||||||||||||||||||||||||||||
| 1416 | on a convention which includes the model name, index and method name. Setting this | ||||||||||||||||||||||||||||||||||||||||||
| 1417 | to true prevents that so you should set C<id> manually unless you don't want them. | ||||||||||||||||||||||||||||||||||||||||||
| 1418 | Please note that even if this is false, you can always override the C<id> on a per | ||||||||||||||||||||||||||||||||||||||||||
| 1419 | field basis by setting it manually. | ||||||||||||||||||||||||||||||||||||||||||
| 1420 | |||||||||||||||||||||||||||||||||||||||||||
| 1421 | B<NOTE> This is a constructor option only; no accessor of this name is provided on | ||||||||||||||||||||||||||||||||||||||||||
| 1422 | the builder. | ||||||||||||||||||||||||||||||||||||||||||
| 1423 | |||||||||||||||||||||||||||||||||||||||||||
| 1424 | =head2 view | ||||||||||||||||||||||||||||||||||||||||||
| 1425 | |||||||||||||||||||||||||||||||||||||||||||
| 1426 | Optional. The view or template object that is using the formbuilder. If available can be used to | ||||||||||||||||||||||||||||||||||||||||||
| 1427 | influence how the HTML for controls are created. | ||||||||||||||||||||||||||||||||||||||||||
| 1428 | |||||||||||||||||||||||||||||||||||||||||||
| 1429 | Generally used to provide HTML escaping and safe string tagging methods that are compatible with | ||||||||||||||||||||||||||||||||||||||||||
| 1430 | your template system. For example L<Mojo::Template> provides its own system for marking strings | ||||||||||||||||||||||||||||||||||||||||||
| 1431 | safe for template display. I you don't provide a view then we will use L<Valiant::HTML::SafeString> | ||||||||||||||||||||||||||||||||||||||||||
| 1432 | for automatic HTML escaping. If you are not using a view or template system (for example like | ||||||||||||||||||||||||||||||||||||||||||
| 1433 | L<Template::Toolkit> ) that does automatic escaping then the built in escaping features are probably | ||||||||||||||||||||||||||||||||||||||||||
| 1434 | fine. | ||||||||||||||||||||||||||||||||||||||||||
| 1435 | |||||||||||||||||||||||||||||||||||||||||||
| 1436 | If you provide a view it should provide the following API methods: | ||||||||||||||||||||||||||||||||||||||||||
| 1437 | |||||||||||||||||||||||||||||||||||||||||||
| 1438 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 1439 | |||||||||||||||||||||||||||||||||||||||||||
| 1440 | =item raw | ||||||||||||||||||||||||||||||||||||||||||
| 1441 | |||||||||||||||||||||||||||||||||||||||||||
| 1442 | given a string return a single tagged object which is marked as safe for display. Do not do any HTML | ||||||||||||||||||||||||||||||||||||||||||
| 1443 | escaping on the string. This is used when you want to pass strings straight to display and that you | ||||||||||||||||||||||||||||||||||||||||||
| 1444 | know is safe. Be careful with this to avoid HTML injection attacks. | ||||||||||||||||||||||||||||||||||||||||||
| 1445 | |||||||||||||||||||||||||||||||||||||||||||
| 1446 | =item safe | ||||||||||||||||||||||||||||||||||||||||||
| 1447 | |||||||||||||||||||||||||||||||||||||||||||
| 1448 | given a string return a single tagged object which is marked as safe for display. First HTML escape the | ||||||||||||||||||||||||||||||||||||||||||
| 1449 | string as safe unless its already been done (no double escaping). | ||||||||||||||||||||||||||||||||||||||||||
| 1450 | |||||||||||||||||||||||||||||||||||||||||||
| 1451 | =item safe_concat | ||||||||||||||||||||||||||||||||||||||||||
| 1452 | |||||||||||||||||||||||||||||||||||||||||||
| 1453 | Same as C<safe> but instead works an an array of strings (or mix of strings and safe string objects) and | ||||||||||||||||||||||||||||||||||||||||||
| 1454 | concatenates them all into one big safe marked string. | ||||||||||||||||||||||||||||||||||||||||||
| 1455 | |||||||||||||||||||||||||||||||||||||||||||
| 1456 | =item html_escape | ||||||||||||||||||||||||||||||||||||||||||
| 1457 | |||||||||||||||||||||||||||||||||||||||||||
| 1458 | Given a string return string that has been HTML escaped. | ||||||||||||||||||||||||||||||||||||||||||
| 1459 | |||||||||||||||||||||||||||||||||||||||||||
| 1460 | =item read_attribute_for_view | ||||||||||||||||||||||||||||||||||||||||||
| 1461 | |||||||||||||||||||||||||||||||||||||||||||
| 1462 | Given an attribute name return the value that the view has defined for it. | ||||||||||||||||||||||||||||||||||||||||||
| 1463 | |||||||||||||||||||||||||||||||||||||||||||
| 1464 | B<NOTE> Optional | ||||||||||||||||||||||||||||||||||||||||||
| 1465 | |||||||||||||||||||||||||||||||||||||||||||
| 1466 | =item attribute_for_view_exists | ||||||||||||||||||||||||||||||||||||||||||
| 1467 | |||||||||||||||||||||||||||||||||||||||||||
| 1468 | Given an attribute name return true if the view has defined a value for it. | ||||||||||||||||||||||||||||||||||||||||||
| 1469 | |||||||||||||||||||||||||||||||||||||||||||
| 1470 | B<NOTE> Optional | ||||||||||||||||||||||||||||||||||||||||||
| 1471 | |||||||||||||||||||||||||||||||||||||||||||
| 1472 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 1473 | |||||||||||||||||||||||||||||||||||||||||||
| 1474 | Both C<raw>, C<safe> and C<safe_concat> should return a 'tagged' object which is specific to your view or | ||||||||||||||||||||||||||||||||||||||||||
| 1475 | template system. However this object must 'stringify' to the safe version of the string to be displayed. See | ||||||||||||||||||||||||||||||||||||||||||
| 1476 | L<Valiant::HTML::SafeString> for example API. We use <Valiant::HTML::SafeString> internally to provide | ||||||||||||||||||||||||||||||||||||||||||
| 1477 | safe escaping if you're view doesn't do automatic escaping, as many older template systems like Template | ||||||||||||||||||||||||||||||||||||||||||
| 1478 | Toolkit. | ||||||||||||||||||||||||||||||||||||||||||
| 1479 | |||||||||||||||||||||||||||||||||||||||||||
| 1480 | B<NOTE>: In the future the view API might change so keep an eye on this spot. | ||||||||||||||||||||||||||||||||||||||||||
| 1481 | |||||||||||||||||||||||||||||||||||||||||||
| 1482 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 1483 | |||||||||||||||||||||||||||||||||||||||||||
| 1484 | This class defines the following public instance methods. | ||||||||||||||||||||||||||||||||||||||||||
| 1485 | |||||||||||||||||||||||||||||||||||||||||||
| 1486 | =head2 form_action | ||||||||||||||||||||||||||||||||||||||||||
| 1487 | |||||||||||||||||||||||||||||||||||||||||||
| 1488 | The Form action attribute | ||||||||||||||||||||||||||||||||||||||||||
| 1489 | |||||||||||||||||||||||||||||||||||||||||||
| 1490 | =head2 form_method | ||||||||||||||||||||||||||||||||||||||||||
| 1491 | |||||||||||||||||||||||||||||||||||||||||||
| 1492 | The form method attribute | ||||||||||||||||||||||||||||||||||||||||||
| 1493 | |||||||||||||||||||||||||||||||||||||||||||
| 1494 | =head2 form_enctype | ||||||||||||||||||||||||||||||||||||||||||
| 1495 | |||||||||||||||||||||||||||||||||||||||||||
| 1496 | the form enctype attribute | ||||||||||||||||||||||||||||||||||||||||||
| 1497 | |||||||||||||||||||||||||||||||||||||||||||
| 1498 | =head2 csrf_token | ||||||||||||||||||||||||||||||||||||||||||
| 1499 | |||||||||||||||||||||||||||||||||||||||||||
| 1500 | The CSRF token, if there is one | ||||||||||||||||||||||||||||||||||||||||||
| 1501 | |||||||||||||||||||||||||||||||||||||||||||
| 1502 | =head2 allow_method_names_outside_object | ||||||||||||||||||||||||||||||||||||||||||
| 1503 | |||||||||||||||||||||||||||||||||||||||||||
| 1504 | accessor to the 'allow_method_names_outside_object' option. This is true by default. Allow you | ||||||||||||||||||||||||||||||||||||||||||
| 1505 | to control the behavior of what happens when you try to access a model attribute that doesn't exist | ||||||||||||||||||||||||||||||||||||||||||
| 1506 | |||||||||||||||||||||||||||||||||||||||||||
| 1507 | =head2 tag_errors_for_attribute | ||||||||||||||||||||||||||||||||||||||||||
| 1508 | |||||||||||||||||||||||||||||||||||||||||||
| 1509 | Given an attribute return an array of error messages for that attribute if any. | ||||||||||||||||||||||||||||||||||||||||||
| 1510 | This calls C<field_errors> on the FormTags object. For this to work you either | ||||||||||||||||||||||||||||||||||||||||||
| 1511 | need a model that responds to C<read_attribute_errors_for> (which tasks a single | ||||||||||||||||||||||||||||||||||||||||||
| 1512 | attribute name and returns an array of error messages) or the model has an | ||||||||||||||||||||||||||||||||||||||||||
| 1513 | C<errors> method that returns a L<Valiant::Errors> object. | ||||||||||||||||||||||||||||||||||||||||||
| 1514 | |||||||||||||||||||||||||||||||||||||||||||
| 1515 | =head2 tag_value_for_attribute | ||||||||||||||||||||||||||||||||||||||||||
| 1516 | |||||||||||||||||||||||||||||||||||||||||||
| 1517 | $fb->tag_value_for_attribute('name'); | ||||||||||||||||||||||||||||||||||||||||||
| 1518 | $fb->tag_value_for_attribute('name', \%options); | ||||||||||||||||||||||||||||||||||||||||||
| 1519 | |||||||||||||||||||||||||||||||||||||||||||
| 1520 | Given an attribute return the value of that attribute on the model. | ||||||||||||||||||||||||||||||||||||||||||
| 1521 | |||||||||||||||||||||||||||||||||||||||||||
| 1522 | Currently the only option is C<no_strict_method_check> which if true will allow you use an attribute | ||||||||||||||||||||||||||||||||||||||||||
| 1523 | name that strictly isn't a method on the model. This is useful if you want to create a form field | ||||||||||||||||||||||||||||||||||||||||||
| 1524 | that doesn't correspond to a model attribute but still respects the current namespace and index. | ||||||||||||||||||||||||||||||||||||||||||
| 1525 | |||||||||||||||||||||||||||||||||||||||||||
| 1526 | You can pass this via the options hashref for most tag generating methods. | ||||||||||||||||||||||||||||||||||||||||||
| 1527 | |||||||||||||||||||||||||||||||||||||||||||
| 1528 | =head2 tag_id_for_attribute | ||||||||||||||||||||||||||||||||||||||||||
| 1529 | |||||||||||||||||||||||||||||||||||||||||||
| 1530 | $fb->tag_id_for_attribute('name'); | ||||||||||||||||||||||||||||||||||||||||||
| 1531 | |||||||||||||||||||||||||||||||||||||||||||
| 1532 | Given an attribute, returns the html C<id> attribute value that the builder would | ||||||||||||||||||||||||||||||||||||||||||
| 1533 | generate for that attribute's form control, respecting the current namespace and | ||||||||||||||||||||||||||||||||||||||||||
| 1534 | index. Useful when writing custom fields or when you need to reference a control | ||||||||||||||||||||||||||||||||||||||||||
| 1535 | from labels or javascript. | ||||||||||||||||||||||||||||||||||||||||||
| 1536 | |||||||||||||||||||||||||||||||||||||||||||
| 1537 | =head2 tag_name_for_attribute | ||||||||||||||||||||||||||||||||||||||||||
| 1538 | |||||||||||||||||||||||||||||||||||||||||||
| 1539 | $fb->tag_name_for_attribute('name'); | ||||||||||||||||||||||||||||||||||||||||||
| 1540 | $fb->tag_name_for_attribute('name', +{multiple=>1}); | ||||||||||||||||||||||||||||||||||||||||||
| 1541 | |||||||||||||||||||||||||||||||||||||||||||
| 1542 | Given an attribute, returns the html C<name> attribute value that the builder would | ||||||||||||||||||||||||||||||||||||||||||
| 1543 | generate for that attribute's form control, respecting the current namespace and | ||||||||||||||||||||||||||||||||||||||||||
| 1544 | index. Pass C<< multiple=>1 >> in the options hashref for controls that submit | ||||||||||||||||||||||||||||||||||||||||||
| 1545 | multiple values (the name gets C<[]> appended). | ||||||||||||||||||||||||||||||||||||||||||
| 1546 | |||||||||||||||||||||||||||||||||||||||||||
| 1547 | =head2 form_action_for | ||||||||||||||||||||||||||||||||||||||||||
| 1548 | |||||||||||||||||||||||||||||||||||||||||||
| 1549 | Usage: | ||||||||||||||||||||||||||||||||||||||||||
| 1550 | |||||||||||||||||||||||||||||||||||||||||||
| 1551 | $fb->form_action_for('path1'); | ||||||||||||||||||||||||||||||||||||||||||
| 1552 | $fb->form_action_for('path1', 'path2'); | ||||||||||||||||||||||||||||||||||||||||||
| 1553 | $fb->form_action_for(\%options); | ||||||||||||||||||||||||||||||||||||||||||
| 1554 | $fb->form_action_for('path1', \%options); | ||||||||||||||||||||||||||||||||||||||||||
| 1555 | $fb->form_action_for('path1', 'path2', \%options); | ||||||||||||||||||||||||||||||||||||||||||
| 1556 | |||||||||||||||||||||||||||||||||||||||||||
| 1557 | Used to create additional URLs under the current form action. Useful if you have form | ||||||||||||||||||||||||||||||||||||||||||
| 1558 | buttons that when activated should go to a different URL than the main form action or | ||||||||||||||||||||||||||||||||||||||||||
| 1559 | where you want to pass query parameters that influence the form action. | ||||||||||||||||||||||||||||||||||||||||||
| 1560 | |||||||||||||||||||||||||||||||||||||||||||
| 1561 | =head2 form_has_errors | ||||||||||||||||||||||||||||||||||||||||||
| 1562 | |||||||||||||||||||||||||||||||||||||||||||
| 1563 | Display a message if the form has errors. This is a convenience method that you can use in your | ||||||||||||||||||||||||||||||||||||||||||
| 1564 | template to display a message if there are any errors in the form. This is useful if you want to | ||||||||||||||||||||||||||||||||||||||||||
| 1565 | display a message at the top of the form. You can also use this method to display a message at the | ||||||||||||||||||||||||||||||||||||||||||
| 1566 | top of a sub formbuilder if you are using sub formbuilders. | ||||||||||||||||||||||||||||||||||||||||||
| 1567 | |||||||||||||||||||||||||||||||||||||||||||
| 1568 | A form has errors if any of the fields has an error or if the model has errors. | ||||||||||||||||||||||||||||||||||||||||||
| 1569 | |||||||||||||||||||||||||||||||||||||||||||
| 1570 | $fb->form_has_errors(); | ||||||||||||||||||||||||||||||||||||||||||
| 1571 | $fb->form_has_errors(\%attrs); | ||||||||||||||||||||||||||||||||||||||||||
| 1572 | $fb->form_has_errors(\%attrs, $content); | ||||||||||||||||||||||||||||||||||||||||||
| 1573 | $fb->form_has_errors(\$content); | ||||||||||||||||||||||||||||||||||||||||||
| 1574 | $fb->form_has_errors(\&template); | ||||||||||||||||||||||||||||||||||||||||||
| 1575 | |||||||||||||||||||||||||||||||||||||||||||
| 1576 | Examples: | ||||||||||||||||||||||||||||||||||||||||||
| 1577 | |||||||||||||||||||||||||||||||||||||||||||
| 1578 | # with default content | ||||||||||||||||||||||||||||||||||||||||||
| 1579 | $fb->form_has_errors; | ||||||||||||||||||||||||||||||||||||||||||
| 1580 | |||||||||||||||||||||||||||||||||||||||||||
| 1581 | # with simple content | ||||||||||||||||||||||||||||||||||||||||||
| 1582 | $fb->form_has_errors('There were errors in the form. Please correct them.'); | ||||||||||||||||||||||||||||||||||||||||||
| 1583 | |||||||||||||||||||||||||||||||||||||||||||
| 1584 | # Simple content with attributes | ||||||||||||||||||||||||||||||||||||||||||
| 1585 | $fb->form_has_errors({ class=>'alert alert-danger', role=>'alert' }, | ||||||||||||||||||||||||||||||||||||||||||
| 1586 | 'There were errors in the form. Please correct them and try again.'); | ||||||||||||||||||||||||||||||||||||||||||
| 1587 | |||||||||||||||||||||||||||||||||||||||||||
| 1588 | # with complex content | ||||||||||||||||||||||||||||||||||||||||||
| 1589 | $fb->form_has_errors(sub ($self, $fb, $contact) { | ||||||||||||||||||||||||||||||||||||||||||
| 1590 | div +{ class=>'alert alert-danger', role=>'alert' }, [ | ||||||||||||||||||||||||||||||||||||||||||
| 1591 | 'There were errors in the form. Please correct them and try again.', | ||||||||||||||||||||||||||||||||||||||||||
| 1592 | ] | ||||||||||||||||||||||||||||||||||||||||||
| 1593 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 1594 | |||||||||||||||||||||||||||||||||||||||||||
| 1595 | If you pass a scalar as content, the scalar can be a string or a translation tag. | ||||||||||||||||||||||||||||||||||||||||||
| 1596 | |||||||||||||||||||||||||||||||||||||||||||
| 1597 | B<Note> Please note this method doesn't show any of the model or field errors, | ||||||||||||||||||||||||||||||||||||||||||
| 1598 | it just shows a generic 'form has errors' message. You can either call the field or | ||||||||||||||||||||||||||||||||||||||||||
| 1599 | L</model_errors> methods, or you can loop over errors in the custom complex | ||||||||||||||||||||||||||||||||||||||||||
| 1600 | content callback. Alternatively if you have model level errors for this object | ||||||||||||||||||||||||||||||||||||||||||
| 1601 | you might prefer to use the L</model_errors> method with the C<show_message_on_field_errors> | ||||||||||||||||||||||||||||||||||||||||||
| 1602 | option. | ||||||||||||||||||||||||||||||||||||||||||
| 1603 | |||||||||||||||||||||||||||||||||||||||||||
| 1604 | =head2 model_errors | ||||||||||||||||||||||||||||||||||||||||||
| 1605 | |||||||||||||||||||||||||||||||||||||||||||
| 1606 | $fb->model_errors(); | ||||||||||||||||||||||||||||||||||||||||||
| 1607 | $fb->model_errors(\%attrs); | ||||||||||||||||||||||||||||||||||||||||||
| 1608 | $fb->model_errors(\%attrs, \&template); # %attrs limited to 'max_errors' and 'show_message_on_field_errors' | ||||||||||||||||||||||||||||||||||||||||||
| 1609 | $fb->model_errors(\&template); | ||||||||||||||||||||||||||||||||||||||||||
| 1610 | |||||||||||||||||||||||||||||||||||||||||||
| 1611 | Display model level errors, either with a default or custom template. 'Model' errors are | ||||||||||||||||||||||||||||||||||||||||||
| 1612 | errors that are not associated with a model attribute in particular, but rather the model | ||||||||||||||||||||||||||||||||||||||||||
| 1613 | as a whole. | ||||||||||||||||||||||||||||||||||||||||||
| 1614 | |||||||||||||||||||||||||||||||||||||||||||
| 1615 | Arguments to this method are optional. "\%attrs" is a hashref which is passed to the tag | ||||||||||||||||||||||||||||||||||||||||||
| 1616 | builder to create any needed HTML attributes (such as class and style). "\&template" is | ||||||||||||||||||||||||||||||||||||||||||
| 1617 | a coderef that gets the @errors as an argument and you can use it to customize how the errors | ||||||||||||||||||||||||||||||||||||||||||
| 1618 | are displayed. Otherwise we use a default template that lists the errors with an HTML ordered | ||||||||||||||||||||||||||||||||||||||||||
| 1619 | list, or a C<div> if there's only one error. | ||||||||||||||||||||||||||||||||||||||||||
| 1620 | |||||||||||||||||||||||||||||||||||||||||||
| 1621 | "\%attrs" can also contain two options that gives you some additional control over the display | ||||||||||||||||||||||||||||||||||||||||||
| 1622 | |||||||||||||||||||||||||||||||||||||||||||
| 1623 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 1624 | |||||||||||||||||||||||||||||||||||||||||||
| 1625 | =item max_errors | ||||||||||||||||||||||||||||||||||||||||||
| 1626 | |||||||||||||||||||||||||||||||||||||||||||
| 1627 | Don't display more than a certain number of errors | ||||||||||||||||||||||||||||||||||||||||||
| 1628 | |||||||||||||||||||||||||||||||||||||||||||
| 1629 | =item show_message_on_field_errors | ||||||||||||||||||||||||||||||||||||||||||
| 1630 | |||||||||||||||||||||||||||||||||||||||||||
| 1631 | Sometimes you want a global message displayed when there are field errors. L<Valiant> doesn't | ||||||||||||||||||||||||||||||||||||||||||
| 1632 | add a model error if there's field errors (although it would be easy for you to add this yourself | ||||||||||||||||||||||||||||||||||||||||||
| 1633 | with a model validation) so this makes it easy to display such a message. If a string or translation | ||||||||||||||||||||||||||||||||||||||||||
| 1634 | tag then show that, if its a '1' the show the default message, which is "Form has errors" unless | ||||||||||||||||||||||||||||||||||||||||||
| 1635 | you overide it. | ||||||||||||||||||||||||||||||||||||||||||
| 1636 | |||||||||||||||||||||||||||||||||||||||||||
| 1637 | This can be a useful option when you have a long form and you want a user to know there's errors | ||||||||||||||||||||||||||||||||||||||||||
| 1638 | possibly off the browser screen. | ||||||||||||||||||||||||||||||||||||||||||
| 1639 | |||||||||||||||||||||||||||||||||||||||||||
| 1640 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 1641 | |||||||||||||||||||||||||||||||||||||||||||
| 1642 | Examples. Assume two model level errors "Trouble 1" and "Trouble 2": | ||||||||||||||||||||||||||||||||||||||||||
| 1643 | |||||||||||||||||||||||||||||||||||||||||||
| 1644 | $fb->model_errors; | ||||||||||||||||||||||||||||||||||||||||||
| 1645 | # <ol><li>Trouble 1</li><li>Trouble 2</li></ol> | ||||||||||||||||||||||||||||||||||||||||||
| 1646 | |||||||||||||||||||||||||||||||||||||||||||
| 1647 | $fb->model_errors({class=>'foo'}); | ||||||||||||||||||||||||||||||||||||||||||
| 1648 | # <ol class="foo"><li>Trouble 1</li><li>Trouble 2</li></ol> | ||||||||||||||||||||||||||||||||||||||||||
| 1649 | |||||||||||||||||||||||||||||||||||||||||||
| 1650 | $fb->model_errors({max_errors=>1}); | ||||||||||||||||||||||||||||||||||||||||||
| 1651 | # <div>Trouble 1</div> | ||||||||||||||||||||||||||||||||||||||||||
| 1652 | |||||||||||||||||||||||||||||||||||||||||||
| 1653 | $fb->model_errors({max_errors=>1, class=>'foo'}) | ||||||||||||||||||||||||||||||||||||||||||
| 1654 | # <div class="foo">Trouble 1</div> | ||||||||||||||||||||||||||||||||||||||||||
| 1655 | |||||||||||||||||||||||||||||||||||||||||||
| 1656 | $fb->model_errors({show_message_on_field_errors=>1}) | ||||||||||||||||||||||||||||||||||||||||||
| 1657 | # <ol><li>Form has errors</li><li>Trouble 1</li><li>Trouble 2</li></ol> | ||||||||||||||||||||||||||||||||||||||||||
| 1658 | |||||||||||||||||||||||||||||||||||||||||||
| 1659 | $fb->model_errors({show_message_on_field_errors=>"Bad!"}) | ||||||||||||||||||||||||||||||||||||||||||
| 1660 | # <ol><li>Bad!</li><li>Trouble 1</li><li>Trouble 2</li></ol> | ||||||||||||||||||||||||||||||||||||||||||
| 1661 | |||||||||||||||||||||||||||||||||||||||||||
| 1662 | $fb->model_errors(sub { | ||||||||||||||||||||||||||||||||||||||||||
| 1663 | my (@errors) = @_; | ||||||||||||||||||||||||||||||||||||||||||
| 1664 | join " | ", @errors; | ||||||||||||||||||||||||||||||||||||||||||
| 1665 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 1666 | # Trouble 1 | Trouble 2 | ||||||||||||||||||||||||||||||||||||||||||
| 1667 | |||||||||||||||||||||||||||||||||||||||||||
| 1668 | =head2 label | ||||||||||||||||||||||||||||||||||||||||||
| 1669 | |||||||||||||||||||||||||||||||||||||||||||
| 1670 | $fb->label($attribute) | ||||||||||||||||||||||||||||||||||||||||||
| 1671 | $fb->label($attribute, \%options) | ||||||||||||||||||||||||||||||||||||||||||
| 1672 | $fb->label($attribute, $content) | ||||||||||||||||||||||||||||||||||||||||||
| 1673 | $fb->label($attribute, \%options, $content) | ||||||||||||||||||||||||||||||||||||||||||
| 1674 | $fb->label($attribute, \&content); sub content { my ($translated_attribute) = @_; ... } | ||||||||||||||||||||||||||||||||||||||||||
| 1675 | $fb->label($attribute, \%options, \&content); sub content { my ( $translated_attribute) = @_; ... } | ||||||||||||||||||||||||||||||||||||||||||
| 1676 | |||||||||||||||||||||||||||||||||||||||||||
| 1677 | Creates a HTML form element C<label> with the given "\%options" passed to the tag builder to | ||||||||||||||||||||||||||||||||||||||||||
| 1678 | create HTML attributes and an optional "$content". If "$content" is not provided we use the | ||||||||||||||||||||||||||||||||||||||||||
| 1679 | human, translated (if available) version of the "$attribute" for the C<label> content. Alternatively | ||||||||||||||||||||||||||||||||||||||||||
| 1680 | you can provide a template which is a subroutine reference which recieves the translated attribute | ||||||||||||||||||||||||||||||||||||||||||
| 1681 | as an argument. Examples: | ||||||||||||||||||||||||||||||||||||||||||
| 1682 | |||||||||||||||||||||||||||||||||||||||||||
| 1683 | $fb->label('first_name'); | ||||||||||||||||||||||||||||||||||||||||||
| 1684 | # <label for="person_first_name">First Name</label> | ||||||||||||||||||||||||||||||||||||||||||
| 1685 | |||||||||||||||||||||||||||||||||||||||||||
| 1686 | $fb->label('first_name', {class=>'foo'}); | ||||||||||||||||||||||||||||||||||||||||||
| 1687 | # <label class="foo" for="person_first_name">First Name</label> | ||||||||||||||||||||||||||||||||||||||||||
| 1688 | |||||||||||||||||||||||||||||||||||||||||||
| 1689 | $fb->label('first_name', 'Your First Name'); | ||||||||||||||||||||||||||||||||||||||||||
| 1690 | # <label for="person_first_name">Your First Name</label> | ||||||||||||||||||||||||||||||||||||||||||
| 1691 | |||||||||||||||||||||||||||||||||||||||||||
| 1692 | $fb->label('first_name', {class=>'foo'}, 'Your First Name'); | ||||||||||||||||||||||||||||||||||||||||||
| 1693 | # <label class="foo" for="person_first_name">Your First Name</label> | ||||||||||||||||||||||||||||||||||||||||||
| 1694 | |||||||||||||||||||||||||||||||||||||||||||
| 1695 | $fb->label('first_name', sub { | ||||||||||||||||||||||||||||||||||||||||||
| 1696 | my $translated_attribute = shift; | ||||||||||||||||||||||||||||||||||||||||||
| 1697 | return "$translated_attribute ", | ||||||||||||||||||||||||||||||||||||||||||
| 1698 | $fb->input('first_name'); | ||||||||||||||||||||||||||||||||||||||||||
| 1699 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 1700 | # <label for="person_first_name"> | ||||||||||||||||||||||||||||||||||||||||||
| 1701 | # First Name | ||||||||||||||||||||||||||||||||||||||||||
| 1702 | # <input id="person_first_name" name="person.first_name" type="text" value="John"/> | ||||||||||||||||||||||||||||||||||||||||||
| 1703 | # </label> | ||||||||||||||||||||||||||||||||||||||||||
| 1704 | |||||||||||||||||||||||||||||||||||||||||||
| 1705 | $fb->label('first_name', +{class=>'foo'}, sub { | ||||||||||||||||||||||||||||||||||||||||||
| 1706 | my $translated_attribute = shift; | ||||||||||||||||||||||||||||||||||||||||||
| 1707 | return "$translated_attribute ", | ||||||||||||||||||||||||||||||||||||||||||
| 1708 | $fb->input('first_name'); | ||||||||||||||||||||||||||||||||||||||||||
| 1709 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 1710 | # <label class="foo" for="person_first_name"> | ||||||||||||||||||||||||||||||||||||||||||
| 1711 | # First Name | ||||||||||||||||||||||||||||||||||||||||||
| 1712 | # <input id="person_first_name" name="person.first_name" type="text" value="John"/> | ||||||||||||||||||||||||||||||||||||||||||
| 1713 | # </label> | ||||||||||||||||||||||||||||||||||||||||||
| 1714 | |||||||||||||||||||||||||||||||||||||||||||
| 1715 | =head2 errors_for | ||||||||||||||||||||||||||||||||||||||||||
| 1716 | |||||||||||||||||||||||||||||||||||||||||||
| 1717 | $fb->errors_for($attribute) | ||||||||||||||||||||||||||||||||||||||||||
| 1718 | $fb->errors_for($attribute, \%options) | ||||||||||||||||||||||||||||||||||||||||||
| 1719 | $fb->errors_for($attribute, \%options, \&template) | ||||||||||||||||||||||||||||||||||||||||||
| 1720 | $fb->errors_for($attribute, \&template) | ||||||||||||||||||||||||||||||||||||||||||
| 1721 | |||||||||||||||||||||||||||||||||||||||||||
| 1722 | Similar to L</model_errors> but for errors associated with an attribute of a model. Accepts | ||||||||||||||||||||||||||||||||||||||||||
| 1723 | the $attribute name, a hashref of \%options (used to set options controling the display of | ||||||||||||||||||||||||||||||||||||||||||
| 1724 | errors as well as used by the tag builder to create HTML attributes for the containing tag) and | ||||||||||||||||||||||||||||||||||||||||||
| 1725 | lastly an optional \&template which is a subroutine reference that received an array of the | ||||||||||||||||||||||||||||||||||||||||||
| 1726 | translated errors for when you need very custom error display. If omitted we use a default | ||||||||||||||||||||||||||||||||||||||||||
| 1727 | template displaying errors in an ordered list (if more than one) or wrapped in a C<div> tag | ||||||||||||||||||||||||||||||||||||||||||
| 1728 | (if only one error). | ||||||||||||||||||||||||||||||||||||||||||
| 1729 | |||||||||||||||||||||||||||||||||||||||||||
| 1730 | \%options used for error display and which are not passed to the tag builder as HTML attributes: | ||||||||||||||||||||||||||||||||||||||||||
| 1731 | |||||||||||||||||||||||||||||||||||||||||||
| 1732 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 1733 | |||||||||||||||||||||||||||||||||||||||||||
| 1734 | =item max_errors | ||||||||||||||||||||||||||||||||||||||||||
| 1735 | |||||||||||||||||||||||||||||||||||||||||||
| 1736 | Don't display more than a certain number of errors | ||||||||||||||||||||||||||||||||||||||||||
| 1737 | |||||||||||||||||||||||||||||||||||||||||||
| 1738 | =item show_empty | ||||||||||||||||||||||||||||||||||||||||||
| 1739 | |||||||||||||||||||||||||||||||||||||||||||
| 1740 | Defaults to false. | ||||||||||||||||||||||||||||||||||||||||||
| 1741 | |||||||||||||||||||||||||||||||||||||||||||
| 1742 | If true then display an empty container even if there are no errors. By default we don't | ||||||||||||||||||||||||||||||||||||||||||
| 1743 | display anything if there are no errors. If you enable this option then you can use the | ||||||||||||||||||||||||||||||||||||||||||
| 1744 | \&template to display a message like "No errors" or something similar. Or you can use CSS | ||||||||||||||||||||||||||||||||||||||||||
| 1745 | to hide the container if there are no errors but need a container if you are also updating | ||||||||||||||||||||||||||||||||||||||||||
| 1746 | the container with AJAX. | ||||||||||||||||||||||||||||||||||||||||||
| 1747 | |||||||||||||||||||||||||||||||||||||||||||
| 1748 | B<NOTE> If you set this to true then C<alway_array> is also set to true UNLESS you've specified | ||||||||||||||||||||||||||||||||||||||||||
| 1749 | a different value. | ||||||||||||||||||||||||||||||||||||||||||
| 1750 | |||||||||||||||||||||||||||||||||||||||||||
| 1751 | =item always_array | ||||||||||||||||||||||||||||||||||||||||||
| 1752 | |||||||||||||||||||||||||||||||||||||||||||
| 1753 | Defaults to false. | ||||||||||||||||||||||||||||||||||||||||||
| 1754 | |||||||||||||||||||||||||||||||||||||||||||
| 1755 | If true then render the default content as if there was more than one error. This is useful | ||||||||||||||||||||||||||||||||||||||||||
| 1756 | if you want to always render the default content as an ordered list even if there's only one | ||||||||||||||||||||||||||||||||||||||||||
| 1757 | error. | ||||||||||||||||||||||||||||||||||||||||||
| 1758 | |||||||||||||||||||||||||||||||||||||||||||
| 1759 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 1760 | |||||||||||||||||||||||||||||||||||||||||||
| 1761 | Assume the attribute 'last_name' has the following two errors in the given examples: "first Name | ||||||||||||||||||||||||||||||||||||||||||
| 1762 | is too short", "First Name contains non alphabetic characters". | ||||||||||||||||||||||||||||||||||||||||||
| 1763 | |||||||||||||||||||||||||||||||||||||||||||
| 1764 | $fb->errors_for('first_name'); | ||||||||||||||||||||||||||||||||||||||||||
| 1765 | # <ol><li>First Name is too short (minimum is 3 characters)</li><li>First Name contains non alphabetic characters</li></ol> | ||||||||||||||||||||||||||||||||||||||||||
| 1766 | |||||||||||||||||||||||||||||||||||||||||||
| 1767 | $fb->errors_for('first_name', {class=>'foo'}); | ||||||||||||||||||||||||||||||||||||||||||
| 1768 | # <ol class="foo"><li>First Name is too short (minimum is 3 characters)</li><li>First Name contains non alphabetic characters</li></ol> | ||||||||||||||||||||||||||||||||||||||||||
| 1769 | |||||||||||||||||||||||||||||||||||||||||||
| 1770 | $fb->errors_for('first_name', {class=>'foo', max_errors=>1}); | ||||||||||||||||||||||||||||||||||||||||||
| 1771 | # <div class="foo">First Name is too short (minimum is 3 characters)</div> | ||||||||||||||||||||||||||||||||||||||||||
| 1772 | |||||||||||||||||||||||||||||||||||||||||||
| 1773 | $fb->errors_for('first_name', sub { | ||||||||||||||||||||||||||||||||||||||||||
| 1774 | my (@errors) = @_; | ||||||||||||||||||||||||||||||||||||||||||
| 1775 | join " | ", @errors; | ||||||||||||||||||||||||||||||||||||||||||
| 1776 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 1777 | # First Name is too short (minimum is 3 characters) | First Name contains non alphabetic characters | ||||||||||||||||||||||||||||||||||||||||||
| 1778 | |||||||||||||||||||||||||||||||||||||||||||
| 1779 | B<NOTE>For this to work the model must either respond to C<read_attribute_errors_for> (which | ||||||||||||||||||||||||||||||||||||||||||
| 1780 | tasks a single attribute name and returns an array of error messages) or the model has an | ||||||||||||||||||||||||||||||||||||||||||
| 1781 | C<errors> method that returns a L<Valiant::Errors> object. If the model does neither then this | ||||||||||||||||||||||||||||||||||||||||||
| 1782 | will always return an empty string. | ||||||||||||||||||||||||||||||||||||||||||
| 1783 | |||||||||||||||||||||||||||||||||||||||||||
| 1784 | =head2 input | ||||||||||||||||||||||||||||||||||||||||||
| 1785 | |||||||||||||||||||||||||||||||||||||||||||
| 1786 | $fb->input($attribute, \%options) | ||||||||||||||||||||||||||||||||||||||||||
| 1787 | $fb->input($attribute) | ||||||||||||||||||||||||||||||||||||||||||
| 1788 | |||||||||||||||||||||||||||||||||||||||||||
| 1789 | Create an C<input> form tag using the $attribute's value (if any) and optionally passing a hashref of | ||||||||||||||||||||||||||||||||||||||||||
| 1790 | \%options which are passed to the tag builder to create HTML attributes for the C<input> tag. Optionally | ||||||||||||||||||||||||||||||||||||||||||
| 1791 | add C<errors_classes> which is a string that is appended to the C<class> attribute when the $attribute has | ||||||||||||||||||||||||||||||||||||||||||
| 1792 | errors. Examples: | ||||||||||||||||||||||||||||||||||||||||||
| 1793 | |||||||||||||||||||||||||||||||||||||||||||
| 1794 | $fb->input('first_name'); | ||||||||||||||||||||||||||||||||||||||||||
| 1795 | # <input id="person_first_name" name="person.first_name" type="text" value="J"/> | ||||||||||||||||||||||||||||||||||||||||||
| 1796 | |||||||||||||||||||||||||||||||||||||||||||
| 1797 | $fb->input('first_name', {class=>'foo'}); | ||||||||||||||||||||||||||||||||||||||||||
| 1798 | # <input class="foo" id="person_first_name" name="person.first_name" type="text" value="J"/> | ||||||||||||||||||||||||||||||||||||||||||
| 1799 | |||||||||||||||||||||||||||||||||||||||||||
| 1800 | $fb->input('first_name', {errors_classes=>'error'}); | ||||||||||||||||||||||||||||||||||||||||||
| 1801 | # <input class="error" id="person_first_name" name="person.first_name" type="text" value="J"/> | ||||||||||||||||||||||||||||||||||||||||||
| 1802 | |||||||||||||||||||||||||||||||||||||||||||
| 1803 | $fb->input('first_name', {class=>'foo', errors_classes=>'error'}); | ||||||||||||||||||||||||||||||||||||||||||
| 1804 | # <input class="foo error" id="person_first_name" name="person.first_name" type="text" value="J"/> | ||||||||||||||||||||||||||||||||||||||||||
| 1805 | |||||||||||||||||||||||||||||||||||||||||||
| 1806 | Special \%options: | ||||||||||||||||||||||||||||||||||||||||||
| 1807 | |||||||||||||||||||||||||||||||||||||||||||
| 1808 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 1809 | |||||||||||||||||||||||||||||||||||||||||||
| 1810 | =item errors_classes | ||||||||||||||||||||||||||||||||||||||||||
| 1811 | |||||||||||||||||||||||||||||||||||||||||||
| 1812 | A string that is appended to the C<class> attribute if the $attribute has errors (as defined by the model API) | ||||||||||||||||||||||||||||||||||||||||||
| 1813 | |||||||||||||||||||||||||||||||||||||||||||
| 1814 | =item force_validity | ||||||||||||||||||||||||||||||||||||||||||
| 1815 | |||||||||||||||||||||||||||||||||||||||||||
| 1816 | Defaults to undefined. Use this if you want to force the field to be either valid or invalid. At | ||||||||||||||||||||||||||||||||||||||||||
| 1817 | this time the only thing this does is control if C<errors_classes> are added to the field. | ||||||||||||||||||||||||||||||||||||||||||
| 1818 | |||||||||||||||||||||||||||||||||||||||||||
| 1819 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 1820 | |||||||||||||||||||||||||||||||||||||||||||
| 1821 | =head2 password | ||||||||||||||||||||||||||||||||||||||||||
| 1822 | |||||||||||||||||||||||||||||||||||||||||||
| 1823 | $fb->password($attribute, \%options) | ||||||||||||||||||||||||||||||||||||||||||
| 1824 | $fb->password($attribute) | ||||||||||||||||||||||||||||||||||||||||||
| 1825 | |||||||||||||||||||||||||||||||||||||||||||
| 1826 | Create a C<password> HTML form field. Similar to L</input> but sets the C<type> to 'password' and also | ||||||||||||||||||||||||||||||||||||||||||
| 1827 | sets C<value> to '' since generally you don't want to show the current password (and if you are doing the | ||||||||||||||||||||||||||||||||||||||||||
| 1828 | right thing and saving a 1 way hash not the plain text you don't even have it to show anyway). | ||||||||||||||||||||||||||||||||||||||||||
| 1829 | |||||||||||||||||||||||||||||||||||||||||||
| 1830 | Example: | ||||||||||||||||||||||||||||||||||||||||||
| 1831 | |||||||||||||||||||||||||||||||||||||||||||
| 1832 | $fb->password('password'); | ||||||||||||||||||||||||||||||||||||||||||
| 1833 | # <input id="person_password" name="person.password" type="password" value=""/> | ||||||||||||||||||||||||||||||||||||||||||
| 1834 | |||||||||||||||||||||||||||||||||||||||||||
| 1835 | $fb->password('password', {class='foo'}); | ||||||||||||||||||||||||||||||||||||||||||
| 1836 | # <input class="foo" id="person_password" name="person.password" type="password" value=""/> | ||||||||||||||||||||||||||||||||||||||||||
| 1837 | |||||||||||||||||||||||||||||||||||||||||||
| 1838 | $fb->password('password', {class='foo', errors_classes=>'error'}); | ||||||||||||||||||||||||||||||||||||||||||
| 1839 | # <input class="foo error" id="person_password" name="person.password" type="password" value=""/> | ||||||||||||||||||||||||||||||||||||||||||
| 1840 | |||||||||||||||||||||||||||||||||||||||||||
| 1841 | =head2 hidden | ||||||||||||||||||||||||||||||||||||||||||
| 1842 | |||||||||||||||||||||||||||||||||||||||||||
| 1843 | $fb->hidden($attribute, \%options) | ||||||||||||||||||||||||||||||||||||||||||
| 1844 | $fb->hidden($attribute) | ||||||||||||||||||||||||||||||||||||||||||
| 1845 | |||||||||||||||||||||||||||||||||||||||||||
| 1846 | Create a C<hidden> HTML form field. Similar to L</input> but sets the C<type> to 'hidden'. | ||||||||||||||||||||||||||||||||||||||||||
| 1847 | |||||||||||||||||||||||||||||||||||||||||||
| 1848 | $fb->hidden('id'); | ||||||||||||||||||||||||||||||||||||||||||
| 1849 | # <input id="person_id name="person.id" type="hidden" value="101"/> | ||||||||||||||||||||||||||||||||||||||||||
| 1850 | |||||||||||||||||||||||||||||||||||||||||||
| 1851 | $fb->hidden('id', {class='foo'}); | ||||||||||||||||||||||||||||||||||||||||||
| 1852 | # <input class="foo" id="person_id name="person.id" type="hidden" value="101"/> | ||||||||||||||||||||||||||||||||||||||||||
| 1853 | |||||||||||||||||||||||||||||||||||||||||||
| 1854 | =head2 text_area | ||||||||||||||||||||||||||||||||||||||||||
| 1855 | |||||||||||||||||||||||||||||||||||||||||||
| 1856 | $fb->text_area($attribute); | ||||||||||||||||||||||||||||||||||||||||||
| 1857 | $fb->text_area($attribute, \%options); | ||||||||||||||||||||||||||||||||||||||||||
| 1858 | |||||||||||||||||||||||||||||||||||||||||||
| 1859 | Create an HTML C<text_area> tag based on the attribute value and with optional \%options | ||||||||||||||||||||||||||||||||||||||||||
| 1860 | which is a a hashref passed to the tag builder for generating HTML attributes. Can also set | ||||||||||||||||||||||||||||||||||||||||||
| 1861 | C<errors_classes> that will append a string of additional CSS classes when the $attribute has | ||||||||||||||||||||||||||||||||||||||||||
| 1862 | errors. Examples: | ||||||||||||||||||||||||||||||||||||||||||
| 1863 | |||||||||||||||||||||||||||||||||||||||||||
| 1864 | $fb->text_area('comments'); | ||||||||||||||||||||||||||||||||||||||||||
| 1865 | # <textarea id="person_comments" name="person.comments">J</textarea> | ||||||||||||||||||||||||||||||||||||||||||
| 1866 | |||||||||||||||||||||||||||||||||||||||||||
| 1867 | $fb->text_area('comments', {class=>'foo'}); | ||||||||||||||||||||||||||||||||||||||||||
| 1868 | # <textarea class="foo" id="person_comments" name="person.comments">J</textarea> | ||||||||||||||||||||||||||||||||||||||||||
| 1869 | |||||||||||||||||||||||||||||||||||||||||||
| 1870 | $fb->text_area('comments', {class=>'foo', errors_classes=>'error'}); | ||||||||||||||||||||||||||||||||||||||||||
| 1871 | # <textarea class="foo error" id="person_comments" name="person.comments">J</textarea> | ||||||||||||||||||||||||||||||||||||||||||
| 1872 | |||||||||||||||||||||||||||||||||||||||||||
| 1873 | Special \%options: | ||||||||||||||||||||||||||||||||||||||||||
| 1874 | |||||||||||||||||||||||||||||||||||||||||||
| 1875 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 1876 | |||||||||||||||||||||||||||||||||||||||||||
| 1877 | =item errors_classes | ||||||||||||||||||||||||||||||||||||||||||
| 1878 | |||||||||||||||||||||||||||||||||||||||||||
| 1879 | A string that is appended to the C<class> attribute if the $attribute has errors (as defined by the model API) | ||||||||||||||||||||||||||||||||||||||||||
| 1880 | |||||||||||||||||||||||||||||||||||||||||||
| 1881 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 1882 | |||||||||||||||||||||||||||||||||||||||||||
| 1883 | =head2 checkbox | ||||||||||||||||||||||||||||||||||||||||||
| 1884 | |||||||||||||||||||||||||||||||||||||||||||
| 1885 | $fb->checkbox($attribute); | ||||||||||||||||||||||||||||||||||||||||||
| 1886 | $fb->checkbox($attribute, \%options); | ||||||||||||||||||||||||||||||||||||||||||
| 1887 | $fb->checkbox($attribute, $checked_value, $unchecked_value); | ||||||||||||||||||||||||||||||||||||||||||
| 1888 | $fb->checkbox($attribute, \%options, $checked_value, $unchecked_value); | ||||||||||||||||||||||||||||||||||||||||||
| 1889 | |||||||||||||||||||||||||||||||||||||||||||
| 1890 | Generate an HTML form checkbox element with its state based on evaluating the value of $attribute | ||||||||||||||||||||||||||||||||||||||||||
| 1891 | in a boolean context. If $attribute is true then the C<checkbox> will be checked. May also pass a | ||||||||||||||||||||||||||||||||||||||||||
| 1892 | hashref of \%options, which contain render instructions and HTML attributes used by the tag builder. | ||||||||||||||||||||||||||||||||||||||||||
| 1893 | "$checked_value" and "$unchecked_value" specify the values when the checkbox is checked or not (defaults | ||||||||||||||||||||||||||||||||||||||||||
| 1894 | to 1 for checked and 0 for unchecked, but $unchecked is ignored if option C<include_hidden> is set to | ||||||||||||||||||||||||||||||||||||||||||
| 1895 | false; see below). | ||||||||||||||||||||||||||||||||||||||||||
| 1896 | |||||||||||||||||||||||||||||||||||||||||||
| 1897 | Special \%options: | ||||||||||||||||||||||||||||||||||||||||||
| 1898 | |||||||||||||||||||||||||||||||||||||||||||
| 1899 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 1900 | |||||||||||||||||||||||||||||||||||||||||||
| 1901 | =item errors_classes | ||||||||||||||||||||||||||||||||||||||||||
| 1902 | |||||||||||||||||||||||||||||||||||||||||||
| 1903 | A string that is appended to the C<class> attribute if the $attribute has errors (as defined by the model API) | ||||||||||||||||||||||||||||||||||||||||||
| 1904 | |||||||||||||||||||||||||||||||||||||||||||
| 1905 | =item include_hidden | ||||||||||||||||||||||||||||||||||||||||||
| 1906 | |||||||||||||||||||||||||||||||||||||||||||
| 1907 | Defaults to true. Since the rules for an HTML form checkbox specify that if the checkbox is 'unchecked' then | ||||||||||||||||||||||||||||||||||||||||||
| 1908 | nothing is submitted. This can cause issues if you are expecting a submission that somehow indicates 'unchecked' | ||||||||||||||||||||||||||||||||||||||||||
| 1909 | For example you might have a status field boolean where unchecked should indicate 'false'. So by default we add | ||||||||||||||||||||||||||||||||||||||||||
| 1910 | a hidden field with the same name as the checkbox, with a value set to $unchecked_value (defaults to 0). In the | ||||||||||||||||||||||||||||||||||||||||||
| 1911 | case where the field is checked then you'll get two values for the same field name so you should have logic that | ||||||||||||||||||||||||||||||||||||||||||
| 1912 | in the case that field name is an array then take the last one (if you are using L<Plack::Request> this is using | ||||||||||||||||||||||||||||||||||||||||||
| 1913 | L<Hash::MultiValue> which does this by default; if you are using L<Catalyst> you can use the C<use_hash_multivalue_in_request> | ||||||||||||||||||||||||||||||||||||||||||
| 1914 | option or you can use something like L<Catalyst::TraitFor::Request::StructuredParameters> which has options to | ||||||||||||||||||||||||||||||||||||||||||
| 1915 | help with this. If you are using L<Mojolicious> then the C<param> method works this way as well. | ||||||||||||||||||||||||||||||||||||||||||
| 1916 | |||||||||||||||||||||||||||||||||||||||||||
| 1917 | =item checked | ||||||||||||||||||||||||||||||||||||||||||
| 1918 | |||||||||||||||||||||||||||||||||||||||||||
| 1919 | A boolean value to indicate if the checkbox field is 'checked' when generated. By default a checkbox state is | ||||||||||||||||||||||||||||||||||||||||||
| 1920 | determined by the value of $attribute for the underlying model. You can use this to override (for example you | ||||||||||||||||||||||||||||||||||||||||||
| 1921 | might wish a checkbox default state to be checked when creating a new entry when it would otherwise be false). | ||||||||||||||||||||||||||||||||||||||||||
| 1922 | |||||||||||||||||||||||||||||||||||||||||||
| 1923 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 1924 | |||||||||||||||||||||||||||||||||||||||||||
| 1925 | Examples: | ||||||||||||||||||||||||||||||||||||||||||
| 1926 | |||||||||||||||||||||||||||||||||||||||||||
| 1927 | $fb->checkbox('status'); | ||||||||||||||||||||||||||||||||||||||||||
| 1928 | # <input name="person.status" type="hidden" value="0"/> | ||||||||||||||||||||||||||||||||||||||||||
| 1929 | # <input id="person_status" name="person.status" type="checkbox" value="1"/> | ||||||||||||||||||||||||||||||||||||||||||
| 1930 | |||||||||||||||||||||||||||||||||||||||||||
| 1931 | $fb->checkbox('status', {class=>'foo'}); | ||||||||||||||||||||||||||||||||||||||||||
| 1932 | # <input name="person.status" type="hidden" value="0"/> | ||||||||||||||||||||||||||||||||||||||||||
| 1933 | # <input class="foo" id="person_status" name="person.status" type="checkbox" value="1"/> | ||||||||||||||||||||||||||||||||||||||||||
| 1934 | |||||||||||||||||||||||||||||||||||||||||||
| 1935 | $fb->checkbox('status', 'active', 'deactive'); | ||||||||||||||||||||||||||||||||||||||||||
| 1936 | # <input name="person.status" type="hidden" value="deactive"/> | ||||||||||||||||||||||||||||||||||||||||||
| 1937 | # <input id="person_status" name="person.status" type="checkbox" value="active"/> | ||||||||||||||||||||||||||||||||||||||||||
| 1938 | |||||||||||||||||||||||||||||||||||||||||||
| 1939 | $fb->checkbox('status', {include_hidden=>0}); | ||||||||||||||||||||||||||||||||||||||||||
| 1940 | # <input id="person_status" name="person.status" type="checkbox" value="1"/> | ||||||||||||||||||||||||||||||||||||||||||
| 1941 | |||||||||||||||||||||||||||||||||||||||||||
| 1942 | $person->status(1); | ||||||||||||||||||||||||||||||||||||||||||
| 1943 | $fb->checkbox('status', {include_hidden=>0}); | ||||||||||||||||||||||||||||||||||||||||||
| 1944 | # <input checked id="person_status" name="person.status" type="checkbox" value="1"/> | ||||||||||||||||||||||||||||||||||||||||||
| 1945 | |||||||||||||||||||||||||||||||||||||||||||
| 1946 | $person->status(0); | ||||||||||||||||||||||||||||||||||||||||||
| 1947 | $fb->checkbox('status', {include_hidden=>0, checked=>1}); | ||||||||||||||||||||||||||||||||||||||||||
| 1948 | # <input checked id="person_status" name="person.status" type="checkbox" value="1"/> | ||||||||||||||||||||||||||||||||||||||||||
| 1949 | |||||||||||||||||||||||||||||||||||||||||||
| 1950 | $fb->checkbox('status', {include_hidden=>0, errors_classes=>'err'}); | ||||||||||||||||||||||||||||||||||||||||||
| 1951 | # <input class="err" id="person_status" name="person.status" type="checkbox" value="1"/> | ||||||||||||||||||||||||||||||||||||||||||
| 1952 | |||||||||||||||||||||||||||||||||||||||||||
| 1953 | =head2 radio_button | ||||||||||||||||||||||||||||||||||||||||||
| 1954 | |||||||||||||||||||||||||||||||||||||||||||
| 1955 | $fb->radio_button($attribute, $value); | ||||||||||||||||||||||||||||||||||||||||||
| 1956 | $fb->radio_button($attribute, $value, \%options); | ||||||||||||||||||||||||||||||||||||||||||
| 1957 | |||||||||||||||||||||||||||||||||||||||||||
| 1958 | Generate an HTML input type 'radio', typically part of a group including 2 or more controls. | ||||||||||||||||||||||||||||||||||||||||||
| 1959 | Generated value attributes uses $value, the control is marked 'checked' when $value matches | ||||||||||||||||||||||||||||||||||||||||||
| 1960 | the value of $attribute (or you can override, see below). \%options are HTML attributes which | ||||||||||||||||||||||||||||||||||||||||||
| 1961 | are passed to the tag builder unless special as described below. | ||||||||||||||||||||||||||||||||||||||||||
| 1962 | |||||||||||||||||||||||||||||||||||||||||||
| 1963 | Special \%options: | ||||||||||||||||||||||||||||||||||||||||||
| 1964 | |||||||||||||||||||||||||||||||||||||||||||
| 1965 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 1966 | |||||||||||||||||||||||||||||||||||||||||||
| 1967 | =item errors_classes | ||||||||||||||||||||||||||||||||||||||||||
| 1968 | |||||||||||||||||||||||||||||||||||||||||||
| 1969 | A string that is appended to the C<class> attribute if the $attribute has errors (as defined by the model API) | ||||||||||||||||||||||||||||||||||||||||||
| 1970 | |||||||||||||||||||||||||||||||||||||||||||
| 1971 | =item checked | ||||||||||||||||||||||||||||||||||||||||||
| 1972 | |||||||||||||||||||||||||||||||||||||||||||
| 1973 | A boolean which determines if the input radio control is marked 'checked'. Used if you want to | ||||||||||||||||||||||||||||||||||||||||||
| 1974 | override the default. | ||||||||||||||||||||||||||||||||||||||||||
| 1975 | |||||||||||||||||||||||||||||||||||||||||||
| 1976 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 1977 | |||||||||||||||||||||||||||||||||||||||||||
| 1978 | Examples: | ||||||||||||||||||||||||||||||||||||||||||
| 1979 | |||||||||||||||||||||||||||||||||||||||||||
| 1980 | # Example radio group | ||||||||||||||||||||||||||||||||||||||||||
| 1981 | |||||||||||||||||||||||||||||||||||||||||||
| 1982 | $person->type('admin'); | ||||||||||||||||||||||||||||||||||||||||||
| 1983 | |||||||||||||||||||||||||||||||||||||||||||
| 1984 | $fb->radio_button('type', 'admin'); | ||||||||||||||||||||||||||||||||||||||||||
| 1985 | $fb->radio_button('type', 'user'); | ||||||||||||||||||||||||||||||||||||||||||
| 1986 | $fb->radio_button('type', 'guest'); | ||||||||||||||||||||||||||||||||||||||||||
| 1987 | |||||||||||||||||||||||||||||||||||||||||||
| 1988 | #<input checked id="person_type_admin" name="person.type" type="radio" value="admin"/> | ||||||||||||||||||||||||||||||||||||||||||
| 1989 | #<input id="person_type_user" name="person.type" type="radio" value="user"/> | ||||||||||||||||||||||||||||||||||||||||||
| 1990 | #<input id="person_type_guest" name="person.type" type="radio" value="guest"/> | ||||||||||||||||||||||||||||||||||||||||||
| 1991 | |||||||||||||||||||||||||||||||||||||||||||
| 1992 | # Example \%options | ||||||||||||||||||||||||||||||||||||||||||
| 1993 | |||||||||||||||||||||||||||||||||||||||||||
| 1994 | $fb->radio_button('type', 'guest', {class=>'foo', errors_classes=>'err'}); | ||||||||||||||||||||||||||||||||||||||||||
| 1995 | # <input class="foo err" id="person_type_guest" name="person.type" type="radio" value="guest"/> | ||||||||||||||||||||||||||||||||||||||||||
| 1996 | |||||||||||||||||||||||||||||||||||||||||||
| 1997 | $fb->radio_button('type', 'guest', {checked=>1}); | ||||||||||||||||||||||||||||||||||||||||||
| 1998 | # <input checked id="person_type_guest" name="person.type" type="radio" value="guest"/> | ||||||||||||||||||||||||||||||||||||||||||
| 1999 | |||||||||||||||||||||||||||||||||||||||||||
| 2000 | =head2 date_field | ||||||||||||||||||||||||||||||||||||||||||
| 2001 | |||||||||||||||||||||||||||||||||||||||||||
| 2002 | $fb->date_field($attribute); | ||||||||||||||||||||||||||||||||||||||||||
| 2003 | $fb->date_field($attribute, \%options); | ||||||||||||||||||||||||||||||||||||||||||
| 2004 | |||||||||||||||||||||||||||||||||||||||||||
| 2005 | Generates a 'type' C<date> HTML input control. Used when your $attribute value is a L<DateTime> | ||||||||||||||||||||||||||||||||||||||||||
| 2006 | object to get proper string formatting. Although the C<date> type is considered HTML5 you can | ||||||||||||||||||||||||||||||||||||||||||
| 2007 | use this for older HTML versions as well when you need to get the object formatting (you just don't | ||||||||||||||||||||||||||||||||||||||||||
| 2008 | get the date HTML controls). | ||||||||||||||||||||||||||||||||||||||||||
| 2009 | |||||||||||||||||||||||||||||||||||||||||||
| 2010 | When the $attribute value is a L<DateTime> object (or actually is any object) we call '->ymd' to stringify | ||||||||||||||||||||||||||||||||||||||||||
| 2011 | the object to the expected format. '\%options' as in the input control are passed to the tag builder | ||||||||||||||||||||||||||||||||||||||||||
| 2012 | to create HTML attributes on the input tag with the exception of the specials ones already documented | ||||||||||||||||||||||||||||||||||||||||||
| 2013 | (such as C<errors_classes>) and the following special \%options | ||||||||||||||||||||||||||||||||||||||||||
| 2014 | |||||||||||||||||||||||||||||||||||||||||||
| 2015 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 2016 | |||||||||||||||||||||||||||||||||||||||||||
| 2017 | =item min | ||||||||||||||||||||||||||||||||||||||||||
| 2018 | |||||||||||||||||||||||||||||||||||||||||||
| 2019 | =item max | ||||||||||||||||||||||||||||||||||||||||||
| 2020 | |||||||||||||||||||||||||||||||||||||||||||
| 2021 | When these are L<DateTime> objects we stringify using ->ymd to get the expected format; otherwise | ||||||||||||||||||||||||||||||||||||||||||
| 2022 | they are passed as is to the tag builder. | ||||||||||||||||||||||||||||||||||||||||||
| 2023 | |||||||||||||||||||||||||||||||||||||||||||
| 2024 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 2025 | |||||||||||||||||||||||||||||||||||||||||||
| 2026 | Examples: | ||||||||||||||||||||||||||||||||||||||||||
| 2027 | |||||||||||||||||||||||||||||||||||||||||||
| 2028 | $person->birthday(DateTime->new(year=>1969, month=>2, day=>13)); | ||||||||||||||||||||||||||||||||||||||||||
| 2029 | |||||||||||||||||||||||||||||||||||||||||||
| 2030 | $fb->date_field('birthday'); | ||||||||||||||||||||||||||||||||||||||||||
| 2031 | # <input id="person_birthday" name="person.birthday" type="date" value="1969-02-13"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2032 | |||||||||||||||||||||||||||||||||||||||||||
| 2033 | $fb->date_field('birthday', {class=>'foo', errors_classes=>'err'}); | ||||||||||||||||||||||||||||||||||||||||||
| 2034 | # <input class="foo err" id="person_birthday" name="person.birthday" type="date" value="1969-02-13"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2035 | |||||||||||||||||||||||||||||||||||||||||||
| 2036 | $fb->date_field('birthday', +{ | ||||||||||||||||||||||||||||||||||||||||||
| 2037 | min => DateTime->new(year=>1900, month=>1, day=>1), | ||||||||||||||||||||||||||||||||||||||||||
| 2038 | max => DateTime->new(year=>2030, month=>1, day=>1), | ||||||||||||||||||||||||||||||||||||||||||
| 2039 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 2040 | #<input id="person_birthday" max="2030-01-01" min="1900-01-01" name="person.birthday" type="date" value="1969-02-13"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2041 | |||||||||||||||||||||||||||||||||||||||||||
| 2042 | =head2 datetime_local_field | ||||||||||||||||||||||||||||||||||||||||||
| 2043 | |||||||||||||||||||||||||||||||||||||||||||
| 2044 | =head2 time_field | ||||||||||||||||||||||||||||||||||||||||||
| 2045 | |||||||||||||||||||||||||||||||||||||||||||
| 2046 | Like L</date_field> but sets the input type to C<datetime-local> or C<time> respectively and formats any | ||||||||||||||||||||||||||||||||||||||||||
| 2047 | <DateTime> values with "->strftime('%Y-%m-%dT%T')" (for C<datetime-local>) or either "->strftime('%H:%M')" | ||||||||||||||||||||||||||||||||||||||||||
| 2048 | or "->strftime('%T.%3N')" for C<time> depending on the \%options C<include_seconds>, which defaults to true). | ||||||||||||||||||||||||||||||||||||||||||
| 2049 | |||||||||||||||||||||||||||||||||||||||||||
| 2050 | Examples: | ||||||||||||||||||||||||||||||||||||||||||
| 2051 | |||||||||||||||||||||||||||||||||||||||||||
| 2052 | $person->due(DateTime->new(year=>1969, month=>2, day=>13, hour=>10, minute=>45, second=>11, nanosecond=> 500000000)); | ||||||||||||||||||||||||||||||||||||||||||
| 2053 | |||||||||||||||||||||||||||||||||||||||||||
| 2054 | $fb->datetime_local_field('due'); | ||||||||||||||||||||||||||||||||||||||||||
| 2055 | # <input id="person_due" name="person.due" type="datetime-local" value="1969-02-13T10:45:11"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2056 | |||||||||||||||||||||||||||||||||||||||||||
| 2057 | $fb->time_field('due'); | ||||||||||||||||||||||||||||||||||||||||||
| 2058 | # <input id="person_due" name="person.due" type="time" value="10:45:11.500"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2059 | |||||||||||||||||||||||||||||||||||||||||||
| 2060 | $fb->time_field('due', +{include_seconds=>0}); | ||||||||||||||||||||||||||||||||||||||||||
| 2061 | # <input id="person_due" name="person.due" type="time" value="10:45"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2062 | |||||||||||||||||||||||||||||||||||||||||||
| 2063 | =head2 submit | ||||||||||||||||||||||||||||||||||||||||||
| 2064 | |||||||||||||||||||||||||||||||||||||||||||
| 2065 | $fb->submit; | ||||||||||||||||||||||||||||||||||||||||||
| 2066 | $fb->submit(\%options); | ||||||||||||||||||||||||||||||||||||||||||
| 2067 | $fb->submit($value); | ||||||||||||||||||||||||||||||||||||||||||
| 2068 | $fb->submit($value, \%options); | ||||||||||||||||||||||||||||||||||||||||||
| 2069 | |||||||||||||||||||||||||||||||||||||||||||
| 2070 | Create an HTML submit C<input> tag with a meaningful default value based on the model name and its state | ||||||||||||||||||||||||||||||||||||||||||
| 2071 | in storage (if supported by the model). Will also look up the following two translation tag keys: | ||||||||||||||||||||||||||||||||||||||||||
| 2072 | |||||||||||||||||||||||||||||||||||||||||||
| 2073 | "formbuilder.submit.@{[ $self->name ]}.${key}" | ||||||||||||||||||||||||||||||||||||||||||
| 2074 | "formbuilder.submit.${key}" | ||||||||||||||||||||||||||||||||||||||||||
| 2075 | |||||||||||||||||||||||||||||||||||||||||||
| 2076 | Where $key is by default 'submit' and if the model supports 'in_storage' its either 'update' or 'create' | ||||||||||||||||||||||||||||||||||||||||||
| 2077 | depending on if the model is new or already existing. | ||||||||||||||||||||||||||||||||||||||||||
| 2078 | |||||||||||||||||||||||||||||||||||||||||||
| 2079 | Examples: | ||||||||||||||||||||||||||||||||||||||||||
| 2080 | |||||||||||||||||||||||||||||||||||||||||||
| 2081 | $fb->submit; | ||||||||||||||||||||||||||||||||||||||||||
| 2082 | # <input id="commit" name="commit" type="submit" value="Submit Person"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2083 | |||||||||||||||||||||||||||||||||||||||||||
| 2084 | $fb->submit('Login', {class=>'foo'}); | ||||||||||||||||||||||||||||||||||||||||||
| 2085 | # <input class="foo" id="commit" name="commit" type="submit" value="Login"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2086 | |||||||||||||||||||||||||||||||||||||||||||
| 2087 | =head2 button | ||||||||||||||||||||||||||||||||||||||||||
| 2088 | |||||||||||||||||||||||||||||||||||||||||||
| 2089 | $fb->button($name, \%attrs, \&block) | ||||||||||||||||||||||||||||||||||||||||||
| 2090 | $fb->button($name, \%attrs, $content) | ||||||||||||||||||||||||||||||||||||||||||
| 2091 | $fb->button($name, \&block) | ||||||||||||||||||||||||||||||||||||||||||
| 2092 | $fb->button($name, $content) | ||||||||||||||||||||||||||||||||||||||||||
| 2093 | |||||||||||||||||||||||||||||||||||||||||||
| 2094 | Create a C<button> tag with custom attibutes and content. Content be be a string or a coderef if you | ||||||||||||||||||||||||||||||||||||||||||
| 2095 | need to do complex layout. | ||||||||||||||||||||||||||||||||||||||||||
| 2096 | |||||||||||||||||||||||||||||||||||||||||||
| 2097 | Useful to create submit buttons with fancy formatting or when you need a button that submits in the | ||||||||||||||||||||||||||||||||||||||||||
| 2098 | form namespace. | ||||||||||||||||||||||||||||||||||||||||||
| 2099 | |||||||||||||||||||||||||||||||||||||||||||
| 2100 | Examples: | ||||||||||||||||||||||||||||||||||||||||||
| 2101 | |||||||||||||||||||||||||||||||||||||||||||
| 2102 | $person->type('admin'); | ||||||||||||||||||||||||||||||||||||||||||
| 2103 | |||||||||||||||||||||||||||||||||||||||||||
| 2104 | $fb->button('type'); | ||||||||||||||||||||||||||||||||||||||||||
| 2105 | # <button id="person_type" name="person.type" type="submit" value="admin">Button</button> | ||||||||||||||||||||||||||||||||||||||||||
| 2106 | |||||||||||||||||||||||||||||||||||||||||||
| 2107 | $fb->button('type', {class=>'foo'}); | ||||||||||||||||||||||||||||||||||||||||||
| 2108 | # <button class="foo" id="person_type" name="person.type" type="submit" value="admin">Button</button> | ||||||||||||||||||||||||||||||||||||||||||
| 2109 | |||||||||||||||||||||||||||||||||||||||||||
| 2110 | $fb->button('type', "Press Me") | ||||||||||||||||||||||||||||||||||||||||||
| 2111 | # <button id="person_type" name="person.type" type="submit" value="admin">Press Me</button> | ||||||||||||||||||||||||||||||||||||||||||
| 2112 | |||||||||||||||||||||||||||||||||||||||||||
| 2113 | $fb->button('type', sub { "Press Me" }) | ||||||||||||||||||||||||||||||||||||||||||
| 2114 | # <button id="person_type" name="person.type" type="submit" value="admin">Press Me</button> | ||||||||||||||||||||||||||||||||||||||||||
| 2115 | |||||||||||||||||||||||||||||||||||||||||||
| 2116 | =head2 legend | ||||||||||||||||||||||||||||||||||||||||||
| 2117 | |||||||||||||||||||||||||||||||||||||||||||
| 2118 | $fb->legend; | ||||||||||||||||||||||||||||||||||||||||||
| 2119 | $fb->legend(\%options); | ||||||||||||||||||||||||||||||||||||||||||
| 2120 | $fb->legend($content); | ||||||||||||||||||||||||||||||||||||||||||
| 2121 | $fb->legend($content, \%options); | ||||||||||||||||||||||||||||||||||||||||||
| 2122 | $fb->legend(\&template); | ||||||||||||||||||||||||||||||||||||||||||
| 2123 | $fb->legend(\%options, \&template); | ||||||||||||||||||||||||||||||||||||||||||
| 2124 | |||||||||||||||||||||||||||||||||||||||||||
| 2125 | Create an HTML Form C<legend> element with default content that is based on the model name. | ||||||||||||||||||||||||||||||||||||||||||
| 2126 | Accepts \%options which are passed to the tag builder and used to create HTML element attributes. | ||||||||||||||||||||||||||||||||||||||||||
| 2127 | You can override the content with either a $content string or a \&template coderef (which will | ||||||||||||||||||||||||||||||||||||||||||
| 2128 | receive the default content translation as its first argument). | ||||||||||||||||||||||||||||||||||||||||||
| 2129 | |||||||||||||||||||||||||||||||||||||||||||
| 2130 | The default content will be based on the model name and can be influenced by its storage status | ||||||||||||||||||||||||||||||||||||||||||
| 2131 | if C<in_storage> is supplied by the model. We attempt to lookup the content string via the | ||||||||||||||||||||||||||||||||||||||||||
| 2132 | following translation tags (if the body supports ->i18n): | ||||||||||||||||||||||||||||||||||||||||||
| 2133 | |||||||||||||||||||||||||||||||||||||||||||
| 2134 | "formbuilder.legend.@{[ $self->name ]}.${key}" | ||||||||||||||||||||||||||||||||||||||||||
| 2135 | "formbuilder.legend.${key}" | ||||||||||||||||||||||||||||||||||||||||||
| 2136 | |||||||||||||||||||||||||||||||||||||||||||
| 2137 | Where $key is 'new' if the model doesn't support C<in_storage> else it's either 'update' or 'create' | ||||||||||||||||||||||||||||||||||||||||||
| 2138 | based on if the current model is already in storage (update) or its new and needs to be created. | ||||||||||||||||||||||||||||||||||||||||||
| 2139 | |||||||||||||||||||||||||||||||||||||||||||
| 2140 | Examples: | ||||||||||||||||||||||||||||||||||||||||||
| 2141 | |||||||||||||||||||||||||||||||||||||||||||
| 2142 | $fb->legend; | ||||||||||||||||||||||||||||||||||||||||||
| 2143 | # <legend>New Person</legend> | ||||||||||||||||||||||||||||||||||||||||||
| 2144 | |||||||||||||||||||||||||||||||||||||||||||
| 2145 | $fb->legend({class=>'foo'}); | ||||||||||||||||||||||||||||||||||||||||||
| 2146 | # <legend class="foo">New Person</legend> | ||||||||||||||||||||||||||||||||||||||||||
| 2147 | |||||||||||||||||||||||||||||||||||||||||||
| 2148 | $fb->legend("Person"); | ||||||||||||||||||||||||||||||||||||||||||
| 2149 | # <legend>Person</legend> | ||||||||||||||||||||||||||||||||||||||||||
| 2150 | |||||||||||||||||||||||||||||||||||||||||||
| 2151 | $fb->legend("Persons", {class=>'foo'}); | ||||||||||||||||||||||||||||||||||||||||||
| 2152 | # <legend class="foo">Persons</legend> | ||||||||||||||||||||||||||||||||||||||||||
| 2153 | |||||||||||||||||||||||||||||||||||||||||||
| 2154 | $fb->legend(sub { shift . " Info"}); | ||||||||||||||||||||||||||||||||||||||||||
| 2155 | # <legend>New Person Info</legend> | ||||||||||||||||||||||||||||||||||||||||||
| 2156 | |||||||||||||||||||||||||||||||||||||||||||
| 2157 | $fb->legend({class=>'foo'}, sub {"Person"}); | ||||||||||||||||||||||||||||||||||||||||||
| 2158 | # <legend class="foo">Person</legend> | ||||||||||||||||||||||||||||||||||||||||||
| 2159 | |||||||||||||||||||||||||||||||||||||||||||
| 2160 | =head2 legend_for | ||||||||||||||||||||||||||||||||||||||||||
| 2161 | |||||||||||||||||||||||||||||||||||||||||||
| 2162 | $fb->legend_for($attr); | ||||||||||||||||||||||||||||||||||||||||||
| 2163 | $fb->legend_for($attr, \%options); | ||||||||||||||||||||||||||||||||||||||||||
| 2164 | |||||||||||||||||||||||||||||||||||||||||||
| 2165 | Creates an HTML C<legend> tags with it's content set to the human translated name of the given | ||||||||||||||||||||||||||||||||||||||||||
| 2166 | $attribute. Allows you to pass some additional HTML attributes to the legend tag. Examples: | ||||||||||||||||||||||||||||||||||||||||||
| 2167 | |||||||||||||||||||||||||||||||||||||||||||
| 2168 | $fb->legend_for('status') | ||||||||||||||||||||||||||||||||||||||||||
| 2169 | # <legend id="status_legend" >Status</legend> | ||||||||||||||||||||||||||||||||||||||||||
| 2170 | |||||||||||||||||||||||||||||||||||||||||||
| 2171 | $fb->legend_for('status', {class=>'foo'}) | ||||||||||||||||||||||||||||||||||||||||||
| 2172 | # <legend id="status_legend" class="foo" >Status</legend> | ||||||||||||||||||||||||||||||||||||||||||
| 2173 | |||||||||||||||||||||||||||||||||||||||||||
| 2174 | =head2 field | ||||||||||||||||||||||||||||||||||||||||||
| 2175 | |||||||||||||||||||||||||||||||||||||||||||
| 2176 | B<EXPERIMENTAL / prototype>: C<field> and the | ||||||||||||||||||||||||||||||||||||||||||
| 2177 | C<Valiant::HTML::FormBuilder::Proxy> it returns are a prototype API that may | ||||||||||||||||||||||||||||||||||||||||||
| 2178 | change or be removed in a future release. | ||||||||||||||||||||||||||||||||||||||||||
| 2179 | |||||||||||||||||||||||||||||||||||||||||||
| 2180 | Returns a proxy scoped to a single attribute, giving a fluent way to build that | ||||||||||||||||||||||||||||||||||||||||||
| 2181 | field's controls. Any FormBuilder method called on the proxy is delegated to | ||||||||||||||||||||||||||||||||||||||||||
| 2182 | the builder with the attribute supplied automatically, and the accumulated | ||||||||||||||||||||||||||||||||||||||||||
| 2183 | parts stringify to the concatenated markup: | ||||||||||||||||||||||||||||||||||||||||||
| 2184 | |||||||||||||||||||||||||||||||||||||||||||
| 2185 | $fb->field('name')->label->input; | ||||||||||||||||||||||||||||||||||||||||||
| 2186 | |||||||||||||||||||||||||||||||||||||||||||
| 2187 | A coderef form is also supported; it receives the proxy: | ||||||||||||||||||||||||||||||||||||||||||
| 2188 | |||||||||||||||||||||||||||||||||||||||||||
| 2189 | $fb->field('name', sub { | ||||||||||||||||||||||||||||||||||||||||||
| 2190 | my $f = shift; | ||||||||||||||||||||||||||||||||||||||||||
| 2191 | $f->label; | ||||||||||||||||||||||||||||||||||||||||||
| 2192 | $f->input; | ||||||||||||||||||||||||||||||||||||||||||
| 2193 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 2194 | |||||||||||||||||||||||||||||||||||||||||||
| 2195 | =head2 fields_for | ||||||||||||||||||||||||||||||||||||||||||
| 2196 | |||||||||||||||||||||||||||||||||||||||||||
| 2197 | $fb->fields_for($attribute, sub { | ||||||||||||||||||||||||||||||||||||||||||
| 2198 | my ($view, $nested_fb, $model) = @_; | ||||||||||||||||||||||||||||||||||||||||||
| 2199 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 2200 | |||||||||||||||||||||||||||||||||||||||||||
| 2201 | $fb->fields_for($attribute, \%options, sub { | ||||||||||||||||||||||||||||||||||||||||||
| 2202 | my ($view, $nested_fb, $model) = @_; | ||||||||||||||||||||||||||||||||||||||||||
| 2203 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 2204 | |||||||||||||||||||||||||||||||||||||||||||
| 2205 | # With a 'finally' block when $attribute is a collection | ||||||||||||||||||||||||||||||||||||||||||
| 2206 | |||||||||||||||||||||||||||||||||||||||||||
| 2207 | $fb->fields_for($attribute, sub { | ||||||||||||||||||||||||||||||||||||||||||
| 2208 | my ($view, $nested_fb, $model) = @_; | ||||||||||||||||||||||||||||||||||||||||||
| 2209 | }, sub { | ||||||||||||||||||||||||||||||||||||||||||
| 2210 | my ($view, $nested_fb, $new_model) = @_; | ||||||||||||||||||||||||||||||||||||||||||
| 2211 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 2212 | |||||||||||||||||||||||||||||||||||||||||||
| 2213 | Where C<$attribute> is a string that refers to a nested object or collection of objects on the model | ||||||||||||||||||||||||||||||||||||||||||
| 2214 | OR its an object or collection of objects itself. | ||||||||||||||||||||||||||||||||||||||||||
| 2215 | |||||||||||||||||||||||||||||||||||||||||||
| 2216 | Used to create sub form builders under the current one for nested models (either a collection of models | ||||||||||||||||||||||||||||||||||||||||||
| 2217 | or a single model.) The enclosing subref receives three arguments: the current view (first), a sub form | ||||||||||||||||||||||||||||||||||||||||||
| 2218 | builder (second) which will encapsulate any indexing or namespacing and whose model will be set to the | ||||||||||||||||||||||||||||||||||||||||||
| 2219 | sub model, and the sub model itself (third) for ease of access. Note that if the $attribute refers to a | ||||||||||||||||||||||||||||||||||||||||||
| 2220 | collection then $model will be set to the current item model of that collection. | ||||||||||||||||||||||||||||||||||||||||||
| 2221 | |||||||||||||||||||||||||||||||||||||||||||
| 2222 | When the $attribute refers to a collection the collection object must provide a C<next> method which should | ||||||||||||||||||||||||||||||||||||||||||
| 2223 | iterate thru the collection in the order desired and return C<undef> to indicate all records have been rolled | ||||||||||||||||||||||||||||||||||||||||||
| 2224 | thru. This collection object may also implement a C<reset> method to return the index to the start of the | ||||||||||||||||||||||||||||||||||||||||||
| 2225 | collection (which will be called after the final record is processed) and a C<build> method which should | ||||||||||||||||||||||||||||||||||||||||||
| 2226 | return a new empty record (required if you want a C<finally> block as described below). | ||||||||||||||||||||||||||||||||||||||||||
| 2227 | |||||||||||||||||||||||||||||||||||||||||||
| 2228 | Please see L<Valiant::HTML::Util::Collection> for example. B<NOTE>: If you supply an arrayref instead of | ||||||||||||||||||||||||||||||||||||||||||
| 2229 | a collection object, we will build one using L<Valiant::HTML::Util::Collection> automatically. This behavior | ||||||||||||||||||||||||||||||||||||||||||
| 2230 | might change in the future so it would be ideal to not rely on it. | ||||||||||||||||||||||||||||||||||||||||||
| 2231 | |||||||||||||||||||||||||||||||||||||||||||
| 2232 | If the $attribute is a collection you may optionally add a second coderef template which is called after | ||||||||||||||||||||||||||||||||||||||||||
| 2233 | the collect has been fully iterated thru and it recieves a sub formbuilder with a new blank model as an | ||||||||||||||||||||||||||||||||||||||||||
| 2234 | argument. This finally block is always called, even if the collection is empty so it can he used to | ||||||||||||||||||||||||||||||||||||||||||
| 2235 | generate a blank entry for adding new items to the collection (for example) or for any extra code or field | ||||||||||||||||||||||||||||||||||||||||||
| 2236 | controls that you want under the sub model namespace. | ||||||||||||||||||||||||||||||||||||||||||
| 2237 | |||||||||||||||||||||||||||||||||||||||||||
| 2238 | Available \%options: | ||||||||||||||||||||||||||||||||||||||||||
| 2239 | |||||||||||||||||||||||||||||||||||||||||||
| 2240 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 2241 | |||||||||||||||||||||||||||||||||||||||||||
| 2242 | =item builder | ||||||||||||||||||||||||||||||||||||||||||
| 2243 | |||||||||||||||||||||||||||||||||||||||||||
| 2244 | The class name of the formbuilder. Defaults to L<Valiant::HTML::FormBuilder> or whatever the current | ||||||||||||||||||||||||||||||||||||||||||
| 2245 | builder is (if overridden in the parent). | ||||||||||||||||||||||||||||||||||||||||||
| 2246 | |||||||||||||||||||||||||||||||||||||||||||
| 2247 | =item namespace | ||||||||||||||||||||||||||||||||||||||||||
| 2248 | |||||||||||||||||||||||||||||||||||||||||||
| 2249 | The ID namespace. Will default to the parent formbuilder C<namespace> if there is one. | ||||||||||||||||||||||||||||||||||||||||||
| 2250 | |||||||||||||||||||||||||||||||||||||||||||
| 2251 | =item child_index | ||||||||||||||||||||||||||||||||||||||||||
| 2252 | |||||||||||||||||||||||||||||||||||||||||||
| 2253 | The index of the sub object. Can be a coderef. Used if you need explicit control over the index generated | ||||||||||||||||||||||||||||||||||||||||||
| 2254 | |||||||||||||||||||||||||||||||||||||||||||
| 2255 | =item include_id | ||||||||||||||||||||||||||||||||||||||||||
| 2256 | |||||||||||||||||||||||||||||||||||||||||||
| 2257 | Defaults to true. If the sub model does C<in_storage> and C<primary_columns> then add hidden form fields | ||||||||||||||||||||||||||||||||||||||||||
| 2258 | with those IDs to the sub model namespace. Often needed to properly match a record to its existing state | ||||||||||||||||||||||||||||||||||||||||||
| 2259 | in storage (such as a database). If you don't want this behavior then set this to false. Or | ||||||||||||||||||||||||||||||||||||||||||
| 2260 | if you want to control where the ids are placed you can set this to false and then use C<emit_hidden_ids> | ||||||||||||||||||||||||||||||||||||||||||
| 2261 | |||||||||||||||||||||||||||||||||||||||||||
| 2262 | =item id | ||||||||||||||||||||||||||||||||||||||||||
| 2263 | |||||||||||||||||||||||||||||||||||||||||||
| 2264 | Override the ID namespace for th sub model. | ||||||||||||||||||||||||||||||||||||||||||
| 2265 | |||||||||||||||||||||||||||||||||||||||||||
| 2266 | =item index | ||||||||||||||||||||||||||||||||||||||||||
| 2267 | |||||||||||||||||||||||||||||||||||||||||||
| 2268 | Explicitly override the index of the sub model. | ||||||||||||||||||||||||||||||||||||||||||
| 2269 | |||||||||||||||||||||||||||||||||||||||||||
| 2270 | =item scope | ||||||||||||||||||||||||||||||||||||||||||
| 2271 | |||||||||||||||||||||||||||||||||||||||||||
| 2272 | Explicitly override the scope of the sub model. | ||||||||||||||||||||||||||||||||||||||||||
| 2273 | |||||||||||||||||||||||||||||||||||||||||||
| 2274 | =item as | ||||||||||||||||||||||||||||||||||||||||||
| 2275 | |||||||||||||||||||||||||||||||||||||||||||
| 2276 | Explicitly override the name of the sub model. | ||||||||||||||||||||||||||||||||||||||||||
| 2277 | |||||||||||||||||||||||||||||||||||||||||||
| 2278 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 2279 | |||||||||||||||||||||||||||||||||||||||||||
| 2280 | Example of an attribute that refers to a nested object. | ||||||||||||||||||||||||||||||||||||||||||
| 2281 | |||||||||||||||||||||||||||||||||||||||||||
| 2282 | $person->profile(Local::Profile->new(zip=>'78621', address=>'ab')); | ||||||||||||||||||||||||||||||||||||||||||
| 2283 | |||||||||||||||||||||||||||||||||||||||||||
| 2284 | $fb->fields_for('profile', sub { | ||||||||||||||||||||||||||||||||||||||||||
| 2285 | my $view = shift; | ||||||||||||||||||||||||||||||||||||||||||
| 2286 | my $fb_profile = shift; | ||||||||||||||||||||||||||||||||||||||||||
| 2287 | return $fb_profile->input('address'), | ||||||||||||||||||||||||||||||||||||||||||
| 2288 | $fb_profile->errors_for('address'), | ||||||||||||||||||||||||||||||||||||||||||
| 2289 | $fb_profile->input('zip'); | ||||||||||||||||||||||||||||||||||||||||||
| 2290 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 2291 | |||||||||||||||||||||||||||||||||||||||||||
| 2292 | # <input id="person_profile_address" name="person.profile.address" type="text" value="ab"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2293 | # <div>Address is too short (minimum is 3 characters)</div> | ||||||||||||||||||||||||||||||||||||||||||
| 2294 | # <input id="person_profile_zip" name="person.profile.zip" type="text" value="78621"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2295 | |||||||||||||||||||||||||||||||||||||||||||
| 2296 | Example of an attribute that refers to a nested collection object (and with a "finally block") | ||||||||||||||||||||||||||||||||||||||||||
| 2297 | |||||||||||||||||||||||||||||||||||||||||||
| 2298 | $person->credit_cards([ | ||||||||||||||||||||||||||||||||||||||||||
| 2299 | Local::CreditCard->new(number=>'234234223444', expiration=>DateTime->now->add(months=>11)), | ||||||||||||||||||||||||||||||||||||||||||
| 2300 | Local::CreditCard->new(number=>'342342342322', expiration=>DateTime->now->add(months=>11)), | ||||||||||||||||||||||||||||||||||||||||||
| 2301 | Local::CreditCard->new(number=>'111112222233', expiration=>DateTime->now->subtract(months=>11)), # An expired card | ||||||||||||||||||||||||||||||||||||||||||
| 2302 | ]); | ||||||||||||||||||||||||||||||||||||||||||
| 2303 | |||||||||||||||||||||||||||||||||||||||||||
| 2304 | $fb->fields_for('credit_cards', sub { | ||||||||||||||||||||||||||||||||||||||||||
| 2305 | my $view = shift; | ||||||||||||||||||||||||||||||||||||||||||
| 2306 | my $fb_cc = shift; | ||||||||||||||||||||||||||||||||||||||||||
| 2307 | return $fb_cc->input('number'), | ||||||||||||||||||||||||||||||||||||||||||
| 2308 | $fb_cc->date_field('expiration'), | ||||||||||||||||||||||||||||||||||||||||||
| 2309 | $fb_cc->errors_for('expiration'); | ||||||||||||||||||||||||||||||||||||||||||
| 2310 | }, sub { | ||||||||||||||||||||||||||||||||||||||||||
| 2311 | my $view = shift; | ||||||||||||||||||||||||||||||||||||||||||
| 2312 | my $fb_finally = shift; | ||||||||||||||||||||||||||||||||||||||||||
| 2313 | return $fb_finally->button('add', +{value=>1}, 'Add a New Credit Card'); | ||||||||||||||||||||||||||||||||||||||||||
| 2314 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 2315 | |||||||||||||||||||||||||||||||||||||||||||
| 2316 | # <input id="person_credit_cards_0_number" name="person.credit_cards[0].number" type="text" value="234234223444"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2317 | # <input id="person_credit_cards_0_expiration" name="person.credit_cards[0].expiration" type="date" value="2023-01-23"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2318 | # <input id="person_credit_cards_1_number" name="person.credit_cards[1].number" type="text" value="342342342322"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2319 | # <input id="person_credit_cards_1_expiration" name="person.credit_cards[1].expiration" type="date" value="2023-01-23"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2320 | # <input id="person_credit_cards_2_number" name="person.credit_cards[2].number" type="text" value="111112222233"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2321 | # <input id="person_credit_cards_2_expiration" name="person.credit_cards[2].expiration" type="date" value="2021-03-23"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2322 | # <div>Expiration chosen date can't be earlier than 2022-02-23</div> | ||||||||||||||||||||||||||||||||||||||||||
| 2323 | # <button id="person_credit_cards_3_add" name="person.credit_cards[3].add" type="submit" value="1">Add a New Credit Card</button> | ||||||||||||||||||||||||||||||||||||||||||
| 2324 | |||||||||||||||||||||||||||||||||||||||||||
| 2325 | =head2 select | ||||||||||||||||||||||||||||||||||||||||||
| 2326 | |||||||||||||||||||||||||||||||||||||||||||
| 2327 | $fb->select($attribute_proto, \@options, \%options) | ||||||||||||||||||||||||||||||||||||||||||
| 2328 | $fb->select($attribute_proto, \@options) | ||||||||||||||||||||||||||||||||||||||||||
| 2329 | $fb->select($attribute_proto, \%options, \&template) | ||||||||||||||||||||||||||||||||||||||||||
| 2330 | $fb->select($attribute_proto, \&template) | ||||||||||||||||||||||||||||||||||||||||||
| 2331 | |||||||||||||||||||||||||||||||||||||||||||
| 2332 | Where C<$attribute_proto> is one of: | ||||||||||||||||||||||||||||||||||||||||||
| 2333 | |||||||||||||||||||||||||||||||||||||||||||
| 2334 | $attribute # A scalar value which is an attribute on the underlying $model | ||||||||||||||||||||||||||||||||||||||||||
| 2335 | { $attribute => $method } # A hashref composed of an $attribute on the underlying $model | ||||||||||||||||||||||||||||||||||||||||||
| 2336 | # which returns a sub model or a collection of sub models | ||||||||||||||||||||||||||||||||||||||||||
| 2337 | # and a $method to be called on the value of that sub model ( | ||||||||||||||||||||||||||||||||||||||||||
| 2338 | # or on each item sub model if the $attribute is a collection). | ||||||||||||||||||||||||||||||||||||||||||
| 2339 | |||||||||||||||||||||||||||||||||||||||||||
| 2340 | Used to create a C<select> tag group with option tags. \@options can be anything that can be | ||||||||||||||||||||||||||||||||||||||||||
| 2341 | accepted by L<Valiant::HTML::FormTags/options_for_select>. The value(s) of $attribute_proto | ||||||||||||||||||||||||||||||||||||||||||
| 2342 | are automatically marked as C<selected>. | ||||||||||||||||||||||||||||||||||||||||||
| 2343 | |||||||||||||||||||||||||||||||||||||||||||
| 2344 | Since this is built on top if C<select_tag> \%options can be anything supported by that | ||||||||||||||||||||||||||||||||||||||||||
| 2345 | method. See L<Valiant::HTML::FormTags/select_tag> for more. In addition we have the following | ||||||||||||||||||||||||||||||||||||||||||
| 2346 | special handling for \%options: | ||||||||||||||||||||||||||||||||||||||||||
| 2347 | |||||||||||||||||||||||||||||||||||||||||||
| 2348 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 2349 | |||||||||||||||||||||||||||||||||||||||||||
| 2350 | =item selected | ||||||||||||||||||||||||||||||||||||||||||
| 2351 | |||||||||||||||||||||||||||||||||||||||||||
| 2352 | =item disabled | ||||||||||||||||||||||||||||||||||||||||||
| 2353 | |||||||||||||||||||||||||||||||||||||||||||
| 2354 | Mark C\<option> tags as selected or disabled. If you manual set selected then we ignore | ||||||||||||||||||||||||||||||||||||||||||
| 2355 | the value of $attribute (or @values when $attribute is a collection) | ||||||||||||||||||||||||||||||||||||||||||
| 2356 | |||||||||||||||||||||||||||||||||||||||||||
| 2357 | =item default_selected | ||||||||||||||||||||||||||||||||||||||||||
| 2358 | |||||||||||||||||||||||||||||||||||||||||||
| 2359 | Use this value to mark selected options ONLY if 'selected' above returns nothing AND the model does | ||||||||||||||||||||||||||||||||||||||||||
| 2360 | not have any values for the given attribute. Useful shortcut to make things as selected for a create | ||||||||||||||||||||||||||||||||||||||||||
| 2361 | field. However this can also be done with correct usage of prefetching into your 'empty' model for | ||||||||||||||||||||||||||||||||||||||||||
| 2362 | create. | ||||||||||||||||||||||||||||||||||||||||||
| 2363 | |||||||||||||||||||||||||||||||||||||||||||
| 2364 | =item unselected_value | ||||||||||||||||||||||||||||||||||||||||||
| 2365 | |||||||||||||||||||||||||||||||||||||||||||
| 2366 | The value to set the hidden 'unselected' field to. No default value. See 'include_hidden' for details. | ||||||||||||||||||||||||||||||||||||||||||
| 2367 | |||||||||||||||||||||||||||||||||||||||||||
| 2368 | =item include_hidden | ||||||||||||||||||||||||||||||||||||||||||
| 2369 | |||||||||||||||||||||||||||||||||||||||||||
| 2370 | Defaults to true for 'multiple' and false for single type selects. | ||||||||||||||||||||||||||||||||||||||||||
| 2371 | |||||||||||||||||||||||||||||||||||||||||||
| 2372 | The rules for an HTML form select field specify that if the no option is 'selected' then | ||||||||||||||||||||||||||||||||||||||||||
| 2373 | nothing is submitted. This can cause issues if you are expecting a submission that somehow indicates 'nothing selected' | ||||||||||||||||||||||||||||||||||||||||||
| 2374 | means to unset some settings. So we do one of two things when 'include_hidden' is true. When the select is a | ||||||||||||||||||||||||||||||||||||||||||
| 2375 | simple 'single value' select (not multiple) we add a hidden field with the same name as the select name but indexed to 0 so its | ||||||||||||||||||||||||||||||||||||||||||
| 2376 | always the first value; its value is whatever you set 'unselected_value' to. If you don't set 'unselected_value' this hidden | ||||||||||||||||||||||||||||||||||||||||||
| 2377 | field is NOT created. If you are using L<Plack::Request> or L<Mojolicious> (or using L<Catalyst> with C<use_hash_multivalue_in_request> option set to | ||||||||||||||||||||||||||||||||||||||||||
| 2378 | true, or something like L<Catalyst::TraitFor::Request::StructuredParameters>) then the last value of an array | ||||||||||||||||||||||||||||||||||||||||||
| 2379 | body parameter will be returned which will let you choose between a default value or an actual returned value. Example: | ||||||||||||||||||||||||||||||||||||||||||
| 2380 | |||||||||||||||||||||||||||||||||||||||||||
| 2381 | # $fb->select('state_ids', [map { [$_->label, $_->id] } $roles_collection->all], +{include_hidden=>1, unselected_value=>-1} ); | ||||||||||||||||||||||||||||||||||||||||||
| 2382 | # <input id="person_state_ids_hidden" name="person.state_ids[0]" type="hidden" value="-1"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2383 | # <select id="person_state_ids" multiple name="person.state_ids[]"> | ||||||||||||||||||||||||||||||||||||||||||
| 2384 | # <option selected value="1">user</option> | ||||||||||||||||||||||||||||||||||||||||||
| 2385 | # <option value="2">admin</option> | ||||||||||||||||||||||||||||||||||||||||||
| 2386 | # <option selected value="3">guest</option> | ||||||||||||||||||||||||||||||||||||||||||
| 2387 | # </select> | ||||||||||||||||||||||||||||||||||||||||||
| 2388 | |||||||||||||||||||||||||||||||||||||||||||
| 2389 | |||||||||||||||||||||||||||||||||||||||||||
| 2390 | If you've set the 'multiple' attribute to true, or we detect that multiple values are intended (either when the form value | ||||||||||||||||||||||||||||||||||||||||||
| 2391 | of the field is an arrayref or a collection) indicting your select drop list allows one to choose more than one option, | ||||||||||||||||||||||||||||||||||||||||||
| 2392 | we add a hidden field '_nop' at index 0 which you will need to treat at the signal for 'this means unset. If you are using this with | ||||||||||||||||||||||||||||||||||||||||||
| 2393 | L<DBIx:Class::Valiant> then that code will automatically handle this for you. Otherwise you'll need to handle it | ||||||||||||||||||||||||||||||||||||||||||
| 2394 | manually or add code to detect that there is no form submission value under that name. If you don't want this | ||||||||||||||||||||||||||||||||||||||||||
| 2395 | behavior you can manually turn it off be explicitly setting 'include_hidden' to false. | ||||||||||||||||||||||||||||||||||||||||||
| 2396 | |||||||||||||||||||||||||||||||||||||||||||
| 2397 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 2398 | |||||||||||||||||||||||||||||||||||||||||||
| 2399 | Optionally you can provide a \&template which should return C<option> tags. This coderef | ||||||||||||||||||||||||||||||||||||||||||
| 2400 | will recieve the $model, $attribute and an array of @selected values based on the $attribute. | ||||||||||||||||||||||||||||||||||||||||||
| 2401 | |||||||||||||||||||||||||||||||||||||||||||
| 2402 | Examples: | ||||||||||||||||||||||||||||||||||||||||||
| 2403 | |||||||||||||||||||||||||||||||||||||||||||
| 2404 | $fb->select('state_id', [1,2,3], +{class=>'foo'} ); | ||||||||||||||||||||||||||||||||||||||||||
| 2405 | # <select class="foo" id="person_state_id" name="person.state_id"> | ||||||||||||||||||||||||||||||||||||||||||
| 2406 | # <option selected value="1">1</option> | ||||||||||||||||||||||||||||||||||||||||||
| 2407 | # <option value="2">2</option> | ||||||||||||||||||||||||||||||||||||||||||
| 2408 | # <option value="3">3</option> | ||||||||||||||||||||||||||||||||||||||||||
| 2409 | # </select> | ||||||||||||||||||||||||||||||||||||||||||
| 2410 | |||||||||||||||||||||||||||||||||||||||||||
| 2411 | $fb->select('state_id', [1,2,3], +{selected=>[3], disabled=>[1]} ); | ||||||||||||||||||||||||||||||||||||||||||
| 2412 | # <select id="person_state_id" name="person.state_id"> | ||||||||||||||||||||||||||||||||||||||||||
| 2413 | # <option disabled value="1">1</option> | ||||||||||||||||||||||||||||||||||||||||||
| 2414 | # <option value="2">2</option> | ||||||||||||||||||||||||||||||||||||||||||
| 2415 | # <option selected value="3">3</option> | ||||||||||||||||||||||||||||||||||||||||||
| 2416 | # </select> | ||||||||||||||||||||||||||||||||||||||||||
| 2417 | |||||||||||||||||||||||||||||||||||||||||||
| 2418 | $fb->select('state_id', [map { [$_->name, $_->id] } $states_collection->all], +{include_blank=>1} ); | ||||||||||||||||||||||||||||||||||||||||||
| 2419 | # <select id="person_state_id" name="person.state_id"> | ||||||||||||||||||||||||||||||||||||||||||
| 2420 | # <option label=" " value=""></option> | ||||||||||||||||||||||||||||||||||||||||||
| 2421 | # <option selected value="1">TX</option> | ||||||||||||||||||||||||||||||||||||||||||
| 2422 | # <option value="2">NY</option> | ||||||||||||||||||||||||||||||||||||||||||
| 2423 | # <option value="3">CA</option> | ||||||||||||||||||||||||||||||||||||||||||
| 2424 | # </select> | ||||||||||||||||||||||||||||||||||||||||||
| 2425 | |||||||||||||||||||||||||||||||||||||||||||
| 2426 | $fb->select('state_id', sub { | ||||||||||||||||||||||||||||||||||||||||||
| 2427 | my ($model, $attribute, $value) = @_; | ||||||||||||||||||||||||||||||||||||||||||
| 2428 | return map { | ||||||||||||||||||||||||||||||||||||||||||
| 2429 | my $selected = $_->id eq $value ? 1:0; | ||||||||||||||||||||||||||||||||||||||||||
| 2430 | option_tag($_->name, +{class=>'foo', selected=>$selected, value=>$_->id}); | ||||||||||||||||||||||||||||||||||||||||||
| 2431 | } $states_collection->all; | ||||||||||||||||||||||||||||||||||||||||||
| 2432 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 2433 | # <select id="person_state_id" name="person.state_id"> | ||||||||||||||||||||||||||||||||||||||||||
| 2434 | # <option class="foo" selected value="1">TX</option> | ||||||||||||||||||||||||||||||||||||||||||
| 2435 | # <option class="foo" value="2">NY</option> | ||||||||||||||||||||||||||||||||||||||||||
| 2436 | # <option class="foo" value="3">CA</option> | ||||||||||||||||||||||||||||||||||||||||||
| 2437 | # </select> | ||||||||||||||||||||||||||||||||||||||||||
| 2438 | |||||||||||||||||||||||||||||||||||||||||||
| 2439 | Examples when $attribute is a collection: | ||||||||||||||||||||||||||||||||||||||||||
| 2440 | |||||||||||||||||||||||||||||||||||||||||||
| 2441 | $fb->select({roles => 'id'}, [map { [$_->label, $_->id] } $roles_collection->all]), | ||||||||||||||||||||||||||||||||||||||||||
| 2442 | # <input id="person_roles_id_hidden" name="person.roles[0]._nop" type="hidden" value="1"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2443 | # <select id="person_roles_id" multiple name="person.roles[].id"> | ||||||||||||||||||||||||||||||||||||||||||
| 2444 | # <option selected value="1">user</option> | ||||||||||||||||||||||||||||||||||||||||||
| 2445 | # <option selected value="2">admin</option> | ||||||||||||||||||||||||||||||||||||||||||
| 2446 | # <option value="3">guest</option> | ||||||||||||||||||||||||||||||||||||||||||
| 2447 | # </select> | ||||||||||||||||||||||||||||||||||||||||||
| 2448 | |||||||||||||||||||||||||||||||||||||||||||
| 2449 | Please note when the $attribute is a collection we add a hidden field to cope with case when | ||||||||||||||||||||||||||||||||||||||||||
| 2450 | no items are selected, you'll need to write form processing code to mark and notice the | ||||||||||||||||||||||||||||||||||||||||||
| 2451 | C<_nop> field. | ||||||||||||||||||||||||||||||||||||||||||
| 2452 | |||||||||||||||||||||||||||||||||||||||||||
| 2453 | =head2 collection_select | ||||||||||||||||||||||||||||||||||||||||||
| 2454 | |||||||||||||||||||||||||||||||||||||||||||
| 2455 | $fb->collection_select($attribute_proto, $collection, $value_method, $text_method, \%options); | ||||||||||||||||||||||||||||||||||||||||||
| 2456 | $fb->collection_select($attribute_proto, $collection, $value_method, $text_method); | ||||||||||||||||||||||||||||||||||||||||||
| 2457 | $fb->collection_select($attribute_proto, $collection); | ||||||||||||||||||||||||||||||||||||||||||
| 2458 | $fb->collection_select($attribute_proto, \%options); | ||||||||||||||||||||||||||||||||||||||||||
| 2459 | |||||||||||||||||||||||||||||||||||||||||||
| 2460 | Where C<$attribute_proto> is one of: | ||||||||||||||||||||||||||||||||||||||||||
| 2461 | |||||||||||||||||||||||||||||||||||||||||||
| 2462 | $attribute # A string which is an attribute on the underlying $model | ||||||||||||||||||||||||||||||||||||||||||
| 2463 | # that returns a scalar value. | ||||||||||||||||||||||||||||||||||||||||||
| 2464 | { $attribute => $method } # A hashref composed of an $attribute on the underlying $model | ||||||||||||||||||||||||||||||||||||||||||
| 2465 | # which returns a sub model or a collection of sub models | ||||||||||||||||||||||||||||||||||||||||||
| 2466 | # and a $method to be called on the value of that sub model ( | ||||||||||||||||||||||||||||||||||||||||||
| 2467 | # or on each item sub model if the $attribute is a collection). | ||||||||||||||||||||||||||||||||||||||||||
| 2468 | |||||||||||||||||||||||||||||||||||||||||||
| 2469 | Similar to L</select> but works with a $collection instead of delineated options. The collection can be | ||||||||||||||||||||||||||||||||||||||||||
| 2470 | an actual collection object, or the string name of a method on the model which provides the actual | ||||||||||||||||||||||||||||||||||||||||||
| 2471 | collection objection. Its a type of shortcut to reduce boilerplate at the expense of some flexibility ( | ||||||||||||||||||||||||||||||||||||||||||
| 2472 | if you need that you'll need to use L</select>). Examples: | ||||||||||||||||||||||||||||||||||||||||||
| 2473 | |||||||||||||||||||||||||||||||||||||||||||
| 2474 | $fb->collection_select('state_id', $states_collection, id=>'name'); | ||||||||||||||||||||||||||||||||||||||||||
| 2475 | # <select id="person.state_id" name="person.state_id"> | ||||||||||||||||||||||||||||||||||||||||||
| 2476 | # <option selected value="1">TX</option> | ||||||||||||||||||||||||||||||||||||||||||
| 2477 | # <option value="2">NY</option> | ||||||||||||||||||||||||||||||||||||||||||
| 2478 | # <option value="3">CA</option> | ||||||||||||||||||||||||||||||||||||||||||
| 2479 | # </select> | ||||||||||||||||||||||||||||||||||||||||||
| 2480 | |||||||||||||||||||||||||||||||||||||||||||
| 2481 | $fb->collection_select('state_id', $states_collection, id=>'name', {class=>'foo', include_blank=>1}); | ||||||||||||||||||||||||||||||||||||||||||
| 2482 | # <select class="foo" id="person.state_id" name="person.state_id"> | ||||||||||||||||||||||||||||||||||||||||||
| 2483 | # <option label=" " value=""></option> | ||||||||||||||||||||||||||||||||||||||||||
| 2484 | # <option selected value="1">TX</option> | ||||||||||||||||||||||||||||||||||||||||||
| 2485 | # <option value="2">NY</option> | ||||||||||||||||||||||||||||||||||||||||||
| 2486 | # <option value="3">CA</option> | ||||||||||||||||||||||||||||||||||||||||||
| 2487 | # </select> | ||||||||||||||||||||||||||||||||||||||||||
| 2488 | |||||||||||||||||||||||||||||||||||||||||||
| 2489 | $fb->collection_select('state_id', $states_collection, id=>'name', {selected=>[3], disabled=>[1]}); | ||||||||||||||||||||||||||||||||||||||||||
| 2490 | # <select id="person.state_id" name="person.state_id"> | ||||||||||||||||||||||||||||||||||||||||||
| 2491 | # <option disabled value="1">TX</option> | ||||||||||||||||||||||||||||||||||||||||||
| 2492 | # <option value="2">NY</option> | ||||||||||||||||||||||||||||||||||||||||||
| 2493 | # <option selected value="3">CA</option> | ||||||||||||||||||||||||||||||||||||||||||
| 2494 | # </select> | ||||||||||||||||||||||||||||||||||||||||||
| 2495 | |||||||||||||||||||||||||||||||||||||||||||
| 2496 | is $fb->collection_select({roles => 'id'}, $roles_collection, id=>'label'); | ||||||||||||||||||||||||||||||||||||||||||
| 2497 | # <input id="person_roles_id_hidden" name="person.roles[0]._nop" type="hidden" value="1"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2498 | # <select id="person_roles_id" multiple name="person.roles[].id"> | ||||||||||||||||||||||||||||||||||||||||||
| 2499 | # <option selected value="1">user</option> | ||||||||||||||||||||||||||||||||||||||||||
| 2500 | # <option selected value="2">admin</option> | ||||||||||||||||||||||||||||||||||||||||||
| 2501 | # <option value="3">guest</option> | ||||||||||||||||||||||||||||||||||||||||||
| 2502 | # </select> | ||||||||||||||||||||||||||||||||||||||||||
| 2503 | |||||||||||||||||||||||||||||||||||||||||||
| 2504 | Please note when the $attribute is a collection value we add a hidden field to allow you to send a signal | ||||||||||||||||||||||||||||||||||||||||||
| 2505 | to the form processor that this namespace contains no records. Otherwise the form will just send | ||||||||||||||||||||||||||||||||||||||||||
| 2506 | nothing. If you have a custom way to handle this you can disable the behavior if you wish by explicitly | ||||||||||||||||||||||||||||||||||||||||||
| 2507 | setting include_hidden=>0 | ||||||||||||||||||||||||||||||||||||||||||
| 2508 | |||||||||||||||||||||||||||||||||||||||||||
| 2509 | \%options follows as from 'select' above. | ||||||||||||||||||||||||||||||||||||||||||
| 2510 | |||||||||||||||||||||||||||||||||||||||||||
| 2511 | =head2 collection_checkbox | ||||||||||||||||||||||||||||||||||||||||||
| 2512 | |||||||||||||||||||||||||||||||||||||||||||
| 2513 | $fb->collection_checkbox({$attribute=>$value_method}, $collection, $value_method, $text_method, \%options); | ||||||||||||||||||||||||||||||||||||||||||
| 2514 | $fb->collection_checkbox({$attribute=>$value_method}, $collection, $value_method, $text_method); | ||||||||||||||||||||||||||||||||||||||||||
| 2515 | $fb->collection_checkbox({$attribute=>$value_method}, $collection); | ||||||||||||||||||||||||||||||||||||||||||
| 2516 | $fb->collection_checkbox({$attribute=>$value_method}, $collection, $value_method, $text_method, \%options, \&template); | ||||||||||||||||||||||||||||||||||||||||||
| 2517 | $fb->collection_checkbox({$attribute=>$value_method}, $collection, $value_method, $text_method, \&template); | ||||||||||||||||||||||||||||||||||||||||||
| 2518 | $fb->collection_checkbox({$attribute=>$value_method}, $collection, \&template); | ||||||||||||||||||||||||||||||||||||||||||
| 2519 | |||||||||||||||||||||||||||||||||||||||||||
| 2520 | Create a checkbox group for a collection attribute | ||||||||||||||||||||||||||||||||||||||||||
| 2521 | |||||||||||||||||||||||||||||||||||||||||||
| 2522 | Examples: | ||||||||||||||||||||||||||||||||||||||||||
| 2523 | |||||||||||||||||||||||||||||||||||||||||||
| 2524 | Where the $attribute C<roles> refers to a collection of sub models, each of which provides a method C<id> | ||||||||||||||||||||||||||||||||||||||||||
| 2525 | which is used to fetch a matching value and $roles_collection refers to the full set of available roles | ||||||||||||||||||||||||||||||||||||||||||
| 2526 | which can be added or removed from the parent model. | ||||||||||||||||||||||||||||||||||||||||||
| 2527 | |||||||||||||||||||||||||||||||||||||||||||
| 2528 | In these examples C<$collection> and C<$roles_collection> can be either a collection object or a string | ||||||||||||||||||||||||||||||||||||||||||
| 2529 | which is the method name on the current model which provides the collection. | ||||||||||||||||||||||||||||||||||||||||||
| 2530 | |||||||||||||||||||||||||||||||||||||||||||
| 2531 | $fb->collection_checkbox({roles => 'id'}, $roles_collection, id=>'label'); | ||||||||||||||||||||||||||||||||||||||||||
| 2532 | # <div id="person_roles"> | ||||||||||||||||||||||||||||||||||||||||||
| 2533 | # <input id="person_roles_hidden" name="person.roles" type="hidden" value="{'_nop':1}"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2534 | # <label for="person_roles_1">user</label> | ||||||||||||||||||||||||||||||||||||||||||
| 2535 | # <input checked id="person_roles_1" name="person.roles" type="checkbox" value="{'id':1}"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2536 | # <label for="person_roles_2">admin</label> | ||||||||||||||||||||||||||||||||||||||||||
| 2537 | # <input checked id="person_roles_2" name="person.roles" type="checkbox" value="{'id':2}"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2538 | # <label for="person_roles_3">guest</label> | ||||||||||||||||||||||||||||||||||||||||||
| 2539 | # <input id="person_roles_3" name="person.roles" type="checkbox" value="{'id':3}"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2540 | # </div> | ||||||||||||||||||||||||||||||||||||||||||
| 2541 | |||||||||||||||||||||||||||||||||||||||||||
| 2542 | Please note when the $attribute is a collection value we add a hidden field to allow you to send a signal | ||||||||||||||||||||||||||||||||||||||||||
| 2543 | to the form processor that this namespace contains no records. Otherwise the form will just send | ||||||||||||||||||||||||||||||||||||||||||
| 2544 | nothing. If you have a custom way to handle this you can disable the behavior if you wish by explicitly | ||||||||||||||||||||||||||||||||||||||||||
| 2545 | setting include_hidden=>0 | ||||||||||||||||||||||||||||||||||||||||||
| 2546 | |||||||||||||||||||||||||||||||||||||||||||
| 2547 | If you have special needs for formatting or layout you can override the default template with a coderef | ||||||||||||||||||||||||||||||||||||||||||
| 2548 | that will receive a special type of formbuilder localized to the current value (an instance of | ||||||||||||||||||||||||||||||||||||||||||
| 2549 | L<Valiant::HTML::FormBuilder::Checkbox>): | ||||||||||||||||||||||||||||||||||||||||||
| 2550 | |||||||||||||||||||||||||||||||||||||||||||
| 2551 | $fb->collection_checkbox({roles => 'id'}, $roles_collection, id=>'label', sub { | ||||||||||||||||||||||||||||||||||||||||||
| 2552 | my $fb_roles = shift; | ||||||||||||||||||||||||||||||||||||||||||
| 2553 | return $fb_roles->checkbox({class=>'form-check-input'}), | ||||||||||||||||||||||||||||||||||||||||||
| 2554 | $fb_roles->label({class=>'form-check-label'}); | ||||||||||||||||||||||||||||||||||||||||||
| 2555 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 2556 | |||||||||||||||||||||||||||||||||||||||||||
| 2557 | # <div id="person_roles"> | ||||||||||||||||||||||||||||||||||||||||||
| 2558 | # <input id="person_roles_hidden" name="person.roles" type="hidden" value="{'_nop':1}"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2559 | # <label for="person_roles_1" class="form-check-label">user</label> | ||||||||||||||||||||||||||||||||||||||||||
| 2560 | # <input checked class="form-check-input" id="person_roles_1" name="person.roles" type="checkbox" value="{'id':1}"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2561 | # <label for="person_roles_2" class="form-check-label">admin</label> | ||||||||||||||||||||||||||||||||||||||||||
| 2562 | # <input checked class="form-check-input" id="person_roles_2" name="person.roles" type="checkbox" value="{'id':2}"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2563 | # <label for="person_roles_3" class="form-check-label">guest</label> | ||||||||||||||||||||||||||||||||||||||||||
| 2564 | # <input class="form-check-input" id="person_roles_3" name="person.roles" type="checkbox" value="{'id':3}"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2565 | # </div> | ||||||||||||||||||||||||||||||||||||||||||
| 2566 | |||||||||||||||||||||||||||||||||||||||||||
| 2567 | In addition to overriding C<checkbox> and C<label> to already contain value and state (if its checked or | ||||||||||||||||||||||||||||||||||||||||||
| 2568 | not) information. This special builder contains some additional methods of possible use, you should see | ||||||||||||||||||||||||||||||||||||||||||
| 2569 | the documentation of L<Valiant::HTML::FormBuilder::Checkbox> for more. | ||||||||||||||||||||||||||||||||||||||||||
| 2570 | |||||||||||||||||||||||||||||||||||||||||||
| 2571 | If provided C<%options> is a hashref of the following optional values | ||||||||||||||||||||||||||||||||||||||||||
| 2572 | |||||||||||||||||||||||||||||||||||||||||||
| 2573 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 2574 | |||||||||||||||||||||||||||||||||||||||||||
| 2575 | =item include_hidden | ||||||||||||||||||||||||||||||||||||||||||
| 2576 | |||||||||||||||||||||||||||||||||||||||||||
| 2577 | Defaults to whatever the method C<default_collection_checkbox_include_hidden> returns. In the core code | ||||||||||||||||||||||||||||||||||||||||||
| 2578 | this returns true. If true will include a hidden field set to the name of the collection, which is uses | ||||||||||||||||||||||||||||||||||||||||||
| 2579 | to indicate 'no checked values' since HTML will send nothing by default if there's no checked values. It | ||||||||||||||||||||||||||||||||||||||||||
| 2580 | will add this hidden field for each checkbox item to represent the 'none checked' value. | ||||||||||||||||||||||||||||||||||||||||||
| 2581 | |||||||||||||||||||||||||||||||||||||||||||
| 2582 | =item builder | ||||||||||||||||||||||||||||||||||||||||||
| 2583 | |||||||||||||||||||||||||||||||||||||||||||
| 2584 | Defaults to the values of C<DEFAULT_COLLECTION_CHECKBOX_BUILDER> method. In core code this is | ||||||||||||||||||||||||||||||||||||||||||
| 2585 | L<Valiant::HTML::FormBuilder::Checkbox>. Overide if you need to make a custom builder (tricky work). | ||||||||||||||||||||||||||||||||||||||||||
| 2586 | |||||||||||||||||||||||||||||||||||||||||||
| 2587 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 2588 | |||||||||||||||||||||||||||||||||||||||||||
| 2589 | =head2 collection_radio_buttons | ||||||||||||||||||||||||||||||||||||||||||
| 2590 | |||||||||||||||||||||||||||||||||||||||||||
| 2591 | $fb->collection_radio_buttons($attribute, $collection, $value_method, $text_method, \%options); | ||||||||||||||||||||||||||||||||||||||||||
| 2592 | $fb->collection_radio_buttons($attribute, $collection, $value_method, $text_method); | ||||||||||||||||||||||||||||||||||||||||||
| 2593 | $fb->collection_radio_buttons($attribute, $collection); | ||||||||||||||||||||||||||||||||||||||||||
| 2594 | $fb->collection_radio_buttons($attribute, $collection, $value_method, $text_method, \%options, \&template); | ||||||||||||||||||||||||||||||||||||||||||
| 2595 | $fb->collection_radio_buttons($attribute, $collection, $value_method, $text_method, \&template); | ||||||||||||||||||||||||||||||||||||||||||
| 2596 | $fb->collection_radio_buttons($attribute, $collection, \&template); | ||||||||||||||||||||||||||||||||||||||||||
| 2597 | |||||||||||||||||||||||||||||||||||||||||||
| 2598 | A collection of radio buttons. Similar to L<\collection_checkbox> but used one only one value is | ||||||||||||||||||||||||||||||||||||||||||
| 2599 | permitted. Example: | ||||||||||||||||||||||||||||||||||||||||||
| 2600 | |||||||||||||||||||||||||||||||||||||||||||
| 2601 | $fb->collection_radio_buttons('state_id', $states_collection, id=>'name'); | ||||||||||||||||||||||||||||||||||||||||||
| 2602 | # <input id="person_state_id_hidden" name="person.state_id" type="hidden" value=""/> | ||||||||||||||||||||||||||||||||||||||||||
| 2603 | # <label for="person_state_id_1">TX</label> | ||||||||||||||||||||||||||||||||||||||||||
| 2604 | # <input checked id="person_state_id_1_1" name="person.state_id" type="radio" value="1"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2605 | # <label for="person_state_id_2">NY</label> | ||||||||||||||||||||||||||||||||||||||||||
| 2606 | # <input id="person_state_id_2_2" name="person.state_id" type="radio" value="2"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2607 | # <label for="person_state_id_3">CA</label> | ||||||||||||||||||||||||||||||||||||||||||
| 2608 | # <input id="person_state_id_3_3" name="person.state_id" type="radio" value="3"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2609 | |||||||||||||||||||||||||||||||||||||||||||
| 2610 | Please note when the $attribute is a collection value we add a hidden field to allow you to send a signal | ||||||||||||||||||||||||||||||||||||||||||
| 2611 | to the form processor that this namespace contains no records. Otherwise the form will just send | ||||||||||||||||||||||||||||||||||||||||||
| 2612 | nothing. If you have a custom way to handle this you can disable the behavior if you wish by explicitly | ||||||||||||||||||||||||||||||||||||||||||
| 2613 | setting include_hidden=>0 | ||||||||||||||||||||||||||||||||||||||||||
| 2614 | |||||||||||||||||||||||||||||||||||||||||||
| 2615 | If you have special needs for formatting or layout you can override the default template with a coderef | ||||||||||||||||||||||||||||||||||||||||||
| 2616 | that will receive a special type of formbuilder localized to the current value (an instance of | ||||||||||||||||||||||||||||||||||||||||||
| 2617 | L<Valiant::HTML::FormBuilder::RadioButton>): | ||||||||||||||||||||||||||||||||||||||||||
| 2618 | |||||||||||||||||||||||||||||||||||||||||||
| 2619 | $fb->collection_radio_buttons('state_id', $states_collection, id=>'name', sub { | ||||||||||||||||||||||||||||||||||||||||||
| 2620 | my $fb_states = shift; | ||||||||||||||||||||||||||||||||||||||||||
| 2621 | return $fb_states->radio_button({class=>'form-check-input'}), | ||||||||||||||||||||||||||||||||||||||||||
| 2622 | $fb_states->label({class=>'form-check-label'}); | ||||||||||||||||||||||||||||||||||||||||||
| 2623 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 2624 | # <div id='person_state_id'> | ||||||||||||||||||||||||||||||||||||||||||
| 2625 | # <input id="person_state_id_hidden" name="person.state_id" type="hidden" value=""/> | ||||||||||||||||||||||||||||||||||||||||||
| 2626 | # <input checked class="form-check-input" id="person_state_id_1_1" name="person.state_id" type="radio" value="1"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2627 | # <label class="form-check-label" for="person_state_id_1">TX</label> | ||||||||||||||||||||||||||||||||||||||||||
| 2628 | # <input class="form-check-input" id="person_state_id_2_2" name="person.state_id" type="radio" value="2"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2629 | # <label class="form-check-label" for="person_state_id_2">NY</label> | ||||||||||||||||||||||||||||||||||||||||||
| 2630 | # <input class="form-check-input" id="person_state_id_3_3" name="person.state_id" type="radio" value="3"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2631 | # <label class="form-check-label" for="person_state_id_3">CA</label> | ||||||||||||||||||||||||||||||||||||||||||
| 2632 | # </div> | ||||||||||||||||||||||||||||||||||||||||||
| 2633 | |||||||||||||||||||||||||||||||||||||||||||
| 2634 | In addition to overriding C<radio_button> and C<label> to already contain value and state (if its checked or | ||||||||||||||||||||||||||||||||||||||||||
| 2635 | not) information. This special builder contains some additional methods of possible use, you should see | ||||||||||||||||||||||||||||||||||||||||||
| 2636 | the documentation of L<Valiant::HTML::FormBuilder::RadioButton> for more. | ||||||||||||||||||||||||||||||||||||||||||
| 2637 | |||||||||||||||||||||||||||||||||||||||||||
| 2638 | Please note that the generated radio inputs will be wrapped in a containing C<div> tag. You can change this tag | ||||||||||||||||||||||||||||||||||||||||||
| 2639 | using the C<container_tag> option. For example: | ||||||||||||||||||||||||||||||||||||||||||
| 2640 | |||||||||||||||||||||||||||||||||||||||||||
| 2641 | $fb->collection_radio_buttons('state_id', $states_collection, id=>'name', +{container_tag=>'span'}, sub { | ||||||||||||||||||||||||||||||||||||||||||
| 2642 | my $fb_states = shift; | ||||||||||||||||||||||||||||||||||||||||||
| 2643 | return $fb_states->radio_button({class=>'form-check-input'}), | ||||||||||||||||||||||||||||||||||||||||||
| 2644 | $fb_states->label({class=>'form-check-label'}); | ||||||||||||||||||||||||||||||||||||||||||
| 2645 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 2646 | |||||||||||||||||||||||||||||||||||||||||||
| 2647 | Here's all the values for the '%options' argument. Any options that are not one of these will be passed to | ||||||||||||||||||||||||||||||||||||||||||
| 2648 | the container tag as html attributes: | ||||||||||||||||||||||||||||||||||||||||||
| 2649 | |||||||||||||||||||||||||||||||||||||||||||
| 2650 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 2651 | |||||||||||||||||||||||||||||||||||||||||||
| 2652 | =item checked_value | ||||||||||||||||||||||||||||||||||||||||||
| 2653 | |||||||||||||||||||||||||||||||||||||||||||
| 2654 | This is the current value of the attribute. By default its the attribute value (via L<\tag_value_for_attribute>) | ||||||||||||||||||||||||||||||||||||||||||
| 2655 | but you can override as needed. | ||||||||||||||||||||||||||||||||||||||||||
| 2656 | |||||||||||||||||||||||||||||||||||||||||||
| 2657 | =item include_hidden. | ||||||||||||||||||||||||||||||||||||||||||
| 2658 | |||||||||||||||||||||||||||||||||||||||||||
| 2659 | Defaults to true. The value returned if you don't check one of the radio buttons. | ||||||||||||||||||||||||||||||||||||||||||
| 2660 | |||||||||||||||||||||||||||||||||||||||||||
| 2661 | =item container_tag | ||||||||||||||||||||||||||||||||||||||||||
| 2662 | |||||||||||||||||||||||||||||||||||||||||||
| 2663 | The tag that contains the generated radio buttons. | ||||||||||||||||||||||||||||||||||||||||||
| 2664 | |||||||||||||||||||||||||||||||||||||||||||
| 2665 | =item builder | ||||||||||||||||||||||||||||||||||||||||||
| 2666 | |||||||||||||||||||||||||||||||||||||||||||
| 2667 | The builder subclass used in the radio input generator. | ||||||||||||||||||||||||||||||||||||||||||
| 2668 | |||||||||||||||||||||||||||||||||||||||||||
| 2669 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 2670 | |||||||||||||||||||||||||||||||||||||||||||
| 2671 | =head2 radio_buttons | ||||||||||||||||||||||||||||||||||||||||||
| 2672 | |||||||||||||||||||||||||||||||||||||||||||
| 2673 | $fb->radio_buttons($attribute, \@options, \%options); | ||||||||||||||||||||||||||||||||||||||||||
| 2674 | $fb->radio_buttons($attribute, \@options, \%options, \&template); | ||||||||||||||||||||||||||||||||||||||||||
| 2675 | $fb->radio_buttons($attribute, \@options); | ||||||||||||||||||||||||||||||||||||||||||
| 2676 | $fb->radio_buttons($attribute, \@options, \&template); | ||||||||||||||||||||||||||||||||||||||||||
| 2677 | |||||||||||||||||||||||||||||||||||||||||||
| 2678 | Similar to L</collection_radio_buttons> but takes an arrayref of label / values instead of a collection. | ||||||||||||||||||||||||||||||||||||||||||
| 2679 | Useful when you have a list of radio buttons (like from an ENUM) but you don't want to list each radio | ||||||||||||||||||||||||||||||||||||||||||
| 2680 | separately. Example: | ||||||||||||||||||||||||||||||||||||||||||
| 2681 | |||||||||||||||||||||||||||||||||||||||||||
| 2682 | $fb_profile->radio_buttons('status', [[Pending=>'pending'],[Active=>'active'],[Inactive=>'inactive']]); | ||||||||||||||||||||||||||||||||||||||||||
| 2683 | |||||||||||||||||||||||||||||||||||||||||||
| 2684 | # <input id="person_profile_status_hidden" name="person.profile.status" type="hidden" value=""> | ||||||||||||||||||||||||||||||||||||||||||
| 2685 | # <input id="person_profile_status_pending_pending" name="person.profile.status" type="radio" value="pending"> | ||||||||||||||||||||||||||||||||||||||||||
| 2686 | # <label for="person_profile_status_pending">Pending</label> | ||||||||||||||||||||||||||||||||||||||||||
| 2687 | # <input checked="" id="person_profile_status_active_actie" name="person.profile.status" type="radio" value="active"> | ||||||||||||||||||||||||||||||||||||||||||
| 2688 | # <label for="person_profile_status_active">Active</label> | ||||||||||||||||||||||||||||||||||||||||||
| 2689 | # <input id="person_profile_status_inactive_inactive" name="person.profile.status" type="radio" value="inactive"> | ||||||||||||||||||||||||||||||||||||||||||
| 2690 | # <label for="person_profile_status_inactive">Inactive</label> | ||||||||||||||||||||||||||||||||||||||||||
| 2691 | |||||||||||||||||||||||||||||||||||||||||||
| 2692 | Supports using a template subroutine reference (like L</collection_radio_buttons>) when you need to be | ||||||||||||||||||||||||||||||||||||||||||
| 2693 | fussy about style and positioning. | ||||||||||||||||||||||||||||||||||||||||||
| 2694 | |||||||||||||||||||||||||||||||||||||||||||
| 2695 | =head2 emit_hidden_ids | ||||||||||||||||||||||||||||||||||||||||||
| 2696 | |||||||||||||||||||||||||||||||||||||||||||
| 2697 | $fb->emit_hidden_ids; | ||||||||||||||||||||||||||||||||||||||||||
| 2698 | |||||||||||||||||||||||||||||||||||||||||||
| 2699 | If the model has C<in_storage> and C<primary_columns> then we will emit hidden fields for each of the | ||||||||||||||||||||||||||||||||||||||||||
| 2700 | primary columns. This is useful when you are editing an existing record and you want to make sure | ||||||||||||||||||||||||||||||||||||||||||
| 2701 | the form submission can be matched to the existing record. Example: | ||||||||||||||||||||||||||||||||||||||||||
| 2702 | |||||||||||||||||||||||||||||||||||||||||||
| 2703 | $fb->emit_hidden_ids; | ||||||||||||||||||||||||||||||||||||||||||
| 2704 | |||||||||||||||||||||||||||||||||||||||||||
| 2705 | # <input id="person_id" name="person.id" type="hidden" value="1"/> | ||||||||||||||||||||||||||||||||||||||||||
| 2706 | |||||||||||||||||||||||||||||||||||||||||||
| 2707 | B<NOTE> In general you should not need to call this method directly. It is called automatically by | ||||||||||||||||||||||||||||||||||||||||||
| 2708 | the form builder when needed. However you might find you need tricky placement of the hidden fields | ||||||||||||||||||||||||||||||||||||||||||
| 2709 | (for example some tricky CSS) and in that case you can call this method manually in fields that allow | ||||||||||||||||||||||||||||||||||||||||||
| 2710 | you to disable the automatic placement of the hidden fields (for example in C<fields_for>, you can set | ||||||||||||||||||||||||||||||||||||||||||
| 2711 | the C<include_id> option to false and then call this method manually). | ||||||||||||||||||||||||||||||||||||||||||
| 2712 | |||||||||||||||||||||||||||||||||||||||||||
| 2713 | =head1 THEMING | ||||||||||||||||||||||||||||||||||||||||||
| 2714 | |||||||||||||||||||||||||||||||||||||||||||
| 2715 | You can add a method called C<default_theme> to your custom form builder sub class to return a hashref of default | ||||||||||||||||||||||||||||||||||||||||||
| 2716 | attributes for the various form elements. For example: | ||||||||||||||||||||||||||||||||||||||||||
| 2717 | |||||||||||||||||||||||||||||||||||||||||||
| 2718 | package Example::FormBuilder; | ||||||||||||||||||||||||||||||||||||||||||
| 2719 | |||||||||||||||||||||||||||||||||||||||||||
| 2720 | use Moo; | ||||||||||||||||||||||||||||||||||||||||||
| 2721 | use Example::Syntax; | ||||||||||||||||||||||||||||||||||||||||||
| 2722 | |||||||||||||||||||||||||||||||||||||||||||
| 2723 | extends 'Valiant::HTML::FormBuilder'; | ||||||||||||||||||||||||||||||||||||||||||
| 2724 | |||||||||||||||||||||||||||||||||||||||||||
| 2725 | sub default_theme($self) { | ||||||||||||||||||||||||||||||||||||||||||
| 2726 | return +{ | ||||||||||||||||||||||||||||||||||||||||||
| 2727 | errors_for => +{ class=>'invalid-feedback' }, | ||||||||||||||||||||||||||||||||||||||||||
| 2728 | label => +{ class=>'form-label' }, | ||||||||||||||||||||||||||||||||||||||||||
| 2729 | input => +{ class=>'form-control', errors_classes=>'is-invalid' }, | ||||||||||||||||||||||||||||||||||||||||||
| 2730 | date_field => +{ class=>'form-control', errors_classes=>'is-invalid' }, | ||||||||||||||||||||||||||||||||||||||||||
| 2731 | password => +{ class=>'form-control', errors_classes=>'is-invalid' }, | ||||||||||||||||||||||||||||||||||||||||||
| 2732 | submit => +{ class=>'btn btn-lg btn-success btn-block' }, | ||||||||||||||||||||||||||||||||||||||||||
| 2733 | button => +{ class=>'btn btn-lg btn-primary btn-block' }, | ||||||||||||||||||||||||||||||||||||||||||
| 2734 | text_area => +{ class=>'form-control' }, | ||||||||||||||||||||||||||||||||||||||||||
| 2735 | checkbox => +{ class=>'form-check-input', errors_classes=>'is-invalid' }, | ||||||||||||||||||||||||||||||||||||||||||
| 2736 | collection_radio_buttons => +{errors_classes=>'is-invalid'}, | ||||||||||||||||||||||||||||||||||||||||||
| 2737 | collection_checkbox => +{errors_classes=>'is-invalid'}, | ||||||||||||||||||||||||||||||||||||||||||
| 2738 | collection_select => +{class=>'form-control', errors_classes=>'is-invalid'}, | ||||||||||||||||||||||||||||||||||||||||||
| 2739 | select => +{class=>'form-control', errors_classes=>'is-invalid'}, | ||||||||||||||||||||||||||||||||||||||||||
| 2740 | radio_buttons => +{errors_classes=>'is-invalid'}, | ||||||||||||||||||||||||||||||||||||||||||
| 2741 | radio_button => +{class=>'custom-control-input', errors_classes=>'is-invalid'}, | ||||||||||||||||||||||||||||||||||||||||||
| 2742 | model_errors => +{ class=>'alert alert-danger', role=>'alert' }, | ||||||||||||||||||||||||||||||||||||||||||
| 2743 | form_has_errors => +{ class=>'alert alert-danger', role=>'alert' }, | ||||||||||||||||||||||||||||||||||||||||||
| 2744 | attributes => { | ||||||||||||||||||||||||||||||||||||||||||
| 2745 | password => { | ||||||||||||||||||||||||||||||||||||||||||
| 2746 | password => { autocomplete=>'new-password' } | ||||||||||||||||||||||||||||||||||||||||||
| 2747 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2748 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 2749 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 2750 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2751 | |||||||||||||||||||||||||||||||||||||||||||
| 2752 | In the above example you set class defaults for most of the form elements based on the method name. In | ||||||||||||||||||||||||||||||||||||||||||
| 2753 | addition you can set specific attributes for specific model attributes (as in the 'password' attribute | ||||||||||||||||||||||||||||||||||||||||||
| 2754 | at the end of the last example. | ||||||||||||||||||||||||||||||||||||||||||
| 2755 | |||||||||||||||||||||||||||||||||||||||||||
| 2756 | Then you you call a method like C<text_field> it will automatically add the default attributes for that | ||||||||||||||||||||||||||||||||||||||||||
| 2757 | element. For example: | ||||||||||||||||||||||||||||||||||||||||||
| 2758 | |||||||||||||||||||||||||||||||||||||||||||
| 2759 | $fb->input('name'); | ||||||||||||||||||||||||||||||||||||||||||
| 2760 | # <input class="form-control" id="person_name" name="person.name" type="text" value=""> | ||||||||||||||||||||||||||||||||||||||||||
| 2761 | |||||||||||||||||||||||||||||||||||||||||||
| 2762 | If you are using a CSS framework you can use this to setup default (but overridable) classes for the various | ||||||||||||||||||||||||||||||||||||||||||
| 2763 | form elements. For example: | ||||||||||||||||||||||||||||||||||||||||||
| 2764 | |||||||||||||||||||||||||||||||||||||||||||
| 2765 | $fb->input('name', {class=>'form-control form-control-lg'}); | ||||||||||||||||||||||||||||||||||||||||||
| 2766 | # <input class="form-control form-control-lg" id="person_name" name="person.name" type="text" value=""> | ||||||||||||||||||||||||||||||||||||||||||
| 2767 | |||||||||||||||||||||||||||||||||||||||||||
| 2768 | You can instead add a method called C<formbuilder_theme> to your view class which does the same thing but | ||||||||||||||||||||||||||||||||||||||||||
| 2769 | allows you to make local view specific customatizations. If you use both the formbuilder default theme is | ||||||||||||||||||||||||||||||||||||||||||
| 2770 | added first and the view theme would override it. | ||||||||||||||||||||||||||||||||||||||||||
| 2771 | |||||||||||||||||||||||||||||||||||||||||||
| 2772 | Please note that you are not limited to passing HTML attributes here, you an pass anything that is a valid | ||||||||||||||||||||||||||||||||||||||||||
| 2773 | attribute for the form field you are generating. | ||||||||||||||||||||||||||||||||||||||||||
| 2774 | |||||||||||||||||||||||||||||||||||||||||||
| 2775 | B<NOTE:> I'm still working out some of the rules around how we merge or override the various themes so if you | ||||||||||||||||||||||||||||||||||||||||||
| 2776 | go wild here you will need to follow the release notes for following versions carefully. I consider theming | ||||||||||||||||||||||||||||||||||||||||||
| 2777 | a beta feature subject to breaking changes if that's what I need to do to fix bugs or make it more flexible. | ||||||||||||||||||||||||||||||||||||||||||
| 2778 | |||||||||||||||||||||||||||||||||||||||||||
| 2779 | 1; | ||||||||||||||||||||||||||||||||||||||||||
| 2780 | |||||||||||||||||||||||||||||||||||||||||||
| 2781 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 2782 | |||||||||||||||||||||||||||||||||||||||||||
| 2783 | L<Valiant> | ||||||||||||||||||||||||||||||||||||||||||
| 2784 | |||||||||||||||||||||||||||||||||||||||||||
| 2785 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 2786 | |||||||||||||||||||||||||||||||||||||||||||
| 2787 | See L<Valiant> | ||||||||||||||||||||||||||||||||||||||||||
| 2788 | |||||||||||||||||||||||||||||||||||||||||||
| 2789 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 2790 | |||||||||||||||||||||||||||||||||||||||||||
| 2791 | See L<Valiant> | ||||||||||||||||||||||||||||||||||||||||||
| 2792 | |||||||||||||||||||||||||||||||||||||||||||
| 2793 | =cut | ||||||||||||||||||||||||||||||||||||||||||