Jump to content

Selector only returning one of two matching records


Kiwi Chris
 Share

Recommended Posts

I have a selector that matches on several fields to provide the records for a page reference field, but is behaving strangely with a couple of records.

The two records use the same template and have identical field values for all fields but for the title and another field pageDescription which are not included in the filter.

Both pages are visible and published, but only one page is returned, although if I do a search directly for the title of the page the selector does not return, it shows up.

Does anyone have any idea why a selector would not return a matching record?

Is there any possibility of database corruption (I'm using InnoDB)

Link to comment
Share on other sites

I've created two identical pages, with only the page-name being different. An ordinary query like

$res = $pages->find("template=basic-page, title|summary|body|sidebar%=muster");
d($res);

correctly returned two matches. The entire DB is innoDB as well. So that surely can't be the culprit.

  • Like 1
Link to comment
Share on other sites

I've tracked down the issue.

Thanks @dragan for the example of how to use d function.

it turns out one field in the selector had a leading space in the record that's not being returned, however it doesn't show in the editor.

By changing the offending field, saving it, then changing it back, it made it have the correct value.

I couldn't just save it, as Processwire didn't consider the field changed, even though it stripped out the leading space before displaying it in the editor.

ie I had a text field productType that was supposed to be "FG" but was actually " FG" however editing the page displayed it as "FG".

The record was orginally imported from CSV, so I either need to get my import to strip leading spaces, or get the editor to display them.

 

 

Link to comment
Share on other sites

On 9/30/2019 at 10:11 AM, Kiwi Chris said:

or get the editor to display them

There is a noTrim setting for InputfieldText and inputfields that extend it.

Quote
noTrim bool By default whitespace is trimmed from value, set this to true to bypass that behavior (default=false).

Hooking InputfieldText::render is too late to set this, but you could hook Field::getInputfield if you want leading/trailing whitespace not to be trimmed for all text fields.

// Include leading/trailing whitespace in inputfields for all text fields
$wire->addHookAfter('Field::getInputfield', function(HookEvent $event) {
	/* @var Inputfield $inputfield */
	$inputfield = $event->return;
	if(!$inputfield instanceof InputfieldText) return;
	$inputfield->noTrim = true;
});

Before:

2019-10-01_161617.png.d123dea63de29e14afe75a1e22633a2d.png

After:

2019-10-01_161640.png.c3d7011e298a534b286ef9206159b7a8.png

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