Jump to content

setMarkup() does not work for Radio buttons (InputfieldRadios)


Valery
 Share

Recommended Posts

Hi people,

I've been trying to tailor the HTML output of my InputfieldRadios, to no avail so far. Here's the code:

$field = $modules->get("InputfieldRadios");
$field->label = 'Radio controls';
$field->attr('id+name', 'radios');
$field->addOption('1', 'Option 1');
$field->attr('value', '1');
$field->addOption('2', 'Option 2');

$form->append($field);        

$form->setMarkup(array(
                'list' => "<div {attrs}>{out}</div>",
                'item' => "<div {attrs}>{out}</div>"
            ));
 

However, I still keep getting <ul> for the radio buttons:

<ul class='InputfieldRadiosStacked'>
                    <li><label><input checked='checked' type='radio' name='radios' id='radios_1' value='1' /> Option 1</label></li>
                    <li><label><input type='radio' name='radios' id='radios_2' value='2' /> Option 2</label></li>
                </ul> 

Is there a way to fix it? I looked into how the admin backend is styled and radio buttons are wrapped in <ul> in there, though the list bullets are removed.

But I'd like my radio buttons wrapped in <div>'s rather than <ul>'s.

Thank you for any hints.

Link to comment
Share on other sites

  • 2 weeks later...

The setMarkup() is just for adjusting the markup of Inputfield lists, not the markup of individual Inputfields. That markup is not currently changeable programatically. Your best bet would be to either:

1) the clean way would be to make a copy of InputfieldRadios => InputfieldRadiosCustom, install as a new module and make it produce the markup you want.

2) the quick n' dirty way would be to replace the <li>'s with <div>'s by hooking after InputfieldRadios::render

wire()->addHookAfter('InputfieldRadios::render', function(HookEvent $e) {
  $e->return = str_replace(
    array('<li ', '</li>'), 
    array('<div ', '</div>'), 
    $e->return); 
}); 
  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...