html-formhandler icon indicating copy to clipboard operation
html-formhandler copied to clipboard

Is there a way to wrap labels of checkbox options?

Open kyzn opened this issue 6 years ago • 0 comments

Hi! Thanks for maintaining HTML::FormHandler. Just had a question about CheckboxGroup & rendering.

Following this documentation, following example works fine: It wraps outer label of checkbox group.

has_field 'my_select' => (
  type     => 'Select',
  label    => 'This is a label',
  widget   => 'CheckboxGroup',
  options  => [
    {value => 'x', label => 'labelx',},
    {value => 'y', label => 'labely',}
  ],
  wrap_label_method => \&wrap_label, # <--- WRAPPING HERE
);

sub wrap_label {
  my ( $self, $label ) = @_;
  return qq{<a href="...">$label</a>};
}

However, I could not get the same to work for labels for each option inside the checkbox. So, for example, this doesn't wrap labels of options.

has_field 'my_select' => (
  type     => 'Select',
  label    => 'This is a label',
  widget   => 'CheckboxGroup',
  options  => [
    {value => 'x', label => 'labelx', wrap_label_method => \&wrap_label, },  # <--- WRAPPING HERE
    {value => 'y', label => 'labely', wrap_label_method => \&wrap_label, },  # <--- WRAPPING HERE
  ],
);

sub wrap_label {
  my ( $self, $label ) = @_;
  return qq{<a href="...">$label</a>};
}

I was wondering if there's an existing way to achieve this. If not, would you be interested in a PR that introduces this functionality?

Thanks a lot!

kyzn avatar Dec 03 '18 09:12 kyzn