Jump to content

Recommended Posts

Posted

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

Posted

I am not saying it will work, but for starters, your selector operator is wrong:

14 minutes ago, Gideon So said:

=%$q

That should be:

%=$q

 

 

Posted
2 hours ago, kongondo said:

I am not saying it will work, but for starters, your selector operator is wrong:

That should be:


%=$q

 

 

Hi,

Typo here. I think I use the right operator in my code. Any more suggestions?

Gideon

Posted

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

Posted

Hi,

The solution is simple.

$pages->find("my_repeater_matrix.my_repeater.my_textarea_field%=$q");

I think I messed up with field name before.

Gideon

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
  • Recently Browsing   0 members

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