has
'parent_builder'
=> (
is
=>
'ro'
,
required
=>1);
sub
default_theme {
my
$self
=
shift
;
return
$self
->parent_builder->can(
'default_theme'
) ?
$self
->parent_builder->default_theme :
+{};
}
sub
text {
my
$self
=
shift
;
return
$self
->tag_value_for_attribute(
$self
->options->{label_method});
}
sub
value {
my
$self
=
shift
;
return
$self
->tag_value_for_attribute(
$self
->options->{value_method});
}
sub
checked {
my
$self
=
shift
;
return
$self
->options->{checked};
}
around
'label'
,
sub
{
my
(
$orig
,
$self
,
$attrs
) =
@_
;
$attrs
= +{}
unless
defined
(
$attrs
);
my
$text
=
$self
->human_name_for_label(
$self
->text);
return
$self
->
$orig
(
$self
->value,
$attrs
,
$text
);
};
around
'radio_button'
,
sub
{
my
(
$orig
,
$self
,
$attrs
) =
@_
;
my
$attribute
=
$self
->options->{attribute};
$attrs
= +{}
unless
defined
(
$attrs
);
$attrs
->{name} =
$self
->name;
$attrs
->{checked} =
$self
->checked;
$attrs
->{id} =
$self
->tag_id_for_attribute(
$self
->value);
$attrs
=
$self
->merge_theme_field_opts(
radio_button
=>
$attrs
->{attribute},
$attrs
);
my
$has_error
= 0;
if
(
my
$errors
=
$self
->options->{errors}) {
foreach
my
$error
(
@$errors
) {
$has_error
= 1
if
$error
->bad_value eq
$self
->value;
}
}
my
$errors_classes
=
exists
(
$attrs
->{errors_classes}) ?
delete
(
$attrs
->{errors_classes}) :
undef
;
$attrs
->{class} =
join
(
' '
, (
grep
{
defined
$_
}
$attrs
->{class},
$errors_classes
))
if
$errors_classes
&&
$has_error
;
return
$self
->
$orig
(
$attribute
,
$self
->value,
$attrs
);
};
1;