HTML::...ioGroup(3pm)

πŸ“¦
version 1.11 Β· 3 versions
, in debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸŽ€ NAME πŸŽ€

HTML::Widget::Element::RadioGroup β€” Radio Element grouping πŸ’…

Okay bestie, quick vibe check: this page lives in the User Contributed Perl Documentation (that's the 3pm section, iykyk). The header up top is all squished down to HTML::...ioGroup(3pm) but the real, full name of the thing is HTML::Widget::Element::RadioGroup and we're gonna treat her with the respect she deserves πŸ‘‘


✨ SYNOPSIS ✨

my $e = $widget->element( 'RadioGroup', 'foo' );
$e->comment('(Required)');
$e->label('Foo'); # label for the whole thing
$e->values([qw/foo bar gorch/]);
$e->labels([qw/Fu Bur Garch/]); # defaults to ucfirst of values
$e->comments([qw/funky/]); # defaults to empty
$e->value("foo"); # the currently selected value
$e->constrain_values(1);

πŸ¦‹ DESCRIPTION πŸ¦‹

It's a RadioGroup Element. That's the whole thing, that's the job 🫢

But here's the important lore, no cap: as of version 1.09, an In constraint is no longer automatically added to RadioGroup elements. So if you want that behaviour back, you gotta go get it yourself with "constrain_values". Periodt πŸ’…


🌸 METHODS 🌸

comment

Add a comment to this Element. Cute little note, love that for you πŸ’¬

label

This label will be placed next to your Element. Right there. Beside it. Besties πŸ’ž

legend

So here's the thing β€” because the RadioGroup gets placed inside a "fieldset" tag, you can also set a </legend> value. 🌈

But heads up babes: if you want your RadioGroup to be styled the same as your other elements, the "label" setting is the one that's recommended. Don't fight it πŸ™ˆ

values

List of form values for radio checks. 🎯 These will also get used as labels if you didn't otherwise specify them via labels.

checked / value

Set which radio element will be pre-set to "checked". βœ…

And "value" is provided as an alias for "checked" β€” same energy, different name, we stan a flexible queen πŸ‘‘

labels

The labels for the corresponding "values". Matchy matchy πŸŽ€

constrain_values

If true, an In constraint will automatically be added to the widget, using the values from "values". That's the auto-magic you were missing since 1.09, babes ✨

retain_default

If true, this overrides the default behaviour β€” so that after a field is missing from the form submission, the xml output will contain the default value, rather than be empty. No more sad empty output πŸ˜­πŸ’–

new

prepare

containerize

id

These ones are listed in the docs but they didn't get a blurb of their own here πŸ™ˆ β€” no description given, so I'm not gonna make one up (that would be lying and lying is not the vibe).


πŸ’… CSS πŸ’…

Horizontal Alignment

To horizontally align the radio buttons with the label, use the following CSS:

.radiogroup > label {
  display: inline;
}

Slay, aligned, immaculate ✨

Changes in version 1.10

Okay so big glow-up alert: a RadioGroup is now rendered using a "fieldset" tag, instead of a "label" tag. Why? Because the individual radio buttons also use labels, and the W3C xhtml specification forbids nested "label" tags. Rude of the spec but okay, we adapt πŸ’…

To make sure RadioGroup elements are styled similar to your other elements, you must change any CSS "label" definitions to also target the RadioGroup's class. That means changing any label { ... } definition into label, .radiogroup_fieldset { ... }. And if you're using the "simple.css" example file, testing with firefox shows you'll also need to add margin: 0em; to that definition to get the label to line up with the other elements. Details matter, bestie πŸ”

If you find the RadioGroup "fieldset" picking up styles that were intended only for other fieldsets, you've got two options, pick your fighter:

  • override those styles with your label, .radiogroup_fieldset { ... } definition, or
  • change your fieldset { ... } definition to .widget_fieldset{ ... } so it specifically targets any Fieldset elements other than the RadioGroup's.

And here's the old-behaviour tea β˜•: previously, if there were any errors, the label tag was given the classname "labels_with_errors". Now, if there's errors, the RadioGroup "fieldset" tag is wrapped in a "span" tag which is given the classname "labels_with_errors". So to ensure that any "labels_with_errors" styles are properly displayed around RadioGroups, you must add display: block; to your .labels_with_errros{ ... } definition.

Note: yes, that's spelled .labels_with_errros in the original β€” with the lil typo and everything. Copy it exactly, do not "fix" it, do not be a hero πŸ’€

πŸ‘€ SEE ALSO πŸ‘€

  • HTML::Widget::Element

Go read that one next, it's giving main character energy 🌟


πŸ‘‘ AUTHOR πŸ‘‘

  • Jess Robinson
  • Yuval Kogman

Legends, both of them, we say thank you πŸ™πŸ’–


πŸ“œ LICENSE πŸ“œ

This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself. Free as in freedom, babes πŸ¦‹


And that's the whole page, bestie!! πŸ’œ This little masterpiece came to you courtesy of perl v5.36.0, dated 2023-08-10, from that HTML::...ioGroup(3pm) page in the User Contributed Perl Documentation. Mwah, go build something cute with it πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from