Jump to content

Search repeater in repeater matrix


Gideon So
 Share

Recommended Posts

I have a repeater matrix field in which there is a repeater field that container a textarea field. How can I search text in the textarea??

I tried $pages->find("repeater_matrix_field.repaeter_field.textarea=%$q"), but return no results.

Any idea how to do it??

Gideon

Link to comment
Share on other sites

This syntax works fine for me with plain Repeater fields, so it should work for Repeater Matrix fields too:

$results = $pages->find("my_repeater.my_nested_repeater.my_textarea%=foo");

So maybe typos are slipping in somewhere else... ;)

Testing this did expose a bug where pages are matched when the repeater fields are empty - will file this at GitHub shortly. Done: https://github.com/processwire/processwire-issues/issues/205

There is another way you could do this, but I think the selector with subfields is more elegant...

// returns the root container page for any repeater item no matter how deeply nested
function getRootContainer($page) {
    if($page instanceof RepeaterPage) {
        return getRootContainer($page->getForPage());
    } else {
        return $page;
    }
}

$results = new PageArray();
$repeater_pages = $pages->find("my_textarea%=foo, has_parent=2, include=all");
foreach($repeater_pages as $repeater_page) {
    $results->add(getRootContainer($repeater_page));
}

 

  • Like 3
Link to comment
Share on other sites

2 hours ago, Robin S said:

This syntax works fine for me with plain Repeater fields, so it should work for Repeater Matrix fields too:


$results = $pages->find("my_repeater.my_nested_repeater.my_textarea%=foo");

 

Hi @Robin S,

I have tried this syntax. Here is my line of code.

$pages->find("repeater_matrix_field.repeater_field.textarea%=$q").

it seems that it does not work in repeater in a repeater matrix context. It still return no results.

Gideon 

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