Jump to content

How to add a markup field to a repeater item?


Jonathan Lahijani
 Share

Recommended Posts

I'm trying to add a markup field to a repeater item.  I would think to use ProcessPageEdit::buildFormContent however that only executes when a page being edited is loaded, not when a repeater item is expanded.

What is the correct hook that would allow me to use the form API and insert a markup field somewhere in the repeater item?

Link to comment
Share on other sites

  • 4 months later...
On 12/5/2023 at 7:46 AM, elabx said:

I would try InputfieldWrapper::render since the repeater items are wrappers themselves ? but not sure super.

As far as I can tell, that's the way to do it.

Assuming your repeater field is called 'my_repeater_field' and it contains a field called 'foo' that you want to add a make-shift markup field above, here's what you'd do:

$wire->addHookAfter('InputfieldWrapper::render', function(HookEvent $event) {
  if(!$event->object->children->count) return;
  if($event->object->children[0]->name!="my_repeater_field") return;
  $event->return = str_replace(
    "<li class='Inputfield InputfieldText Inputfield_foo_repeater",
    "
    <li class='Inputfield'>
        <label class='InputfieldHeader'>
            my custom repeater markup field
        </label>
        <div class='InputfieldContent'>
            content goes here
        </div>
    </li>
    <li class='Inputfield InputfieldText Inputfield_foo_repeater",
    $event->return
  );
});

 

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...