Jump to content
Kiwi Chris

Selector only returning one of two matching records

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)

Share this post


Link to post
Share on other sites

Can you post your selector query?

What version of ProcessWire are you using?

Is one of the pages hidden? Is there something special with your pages or templates?

Are these pages not visible to guests or admin users or everyone?

  • Like 1

Share this post


Link to post
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

Share this post


Link to post
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.

 

 

Share this post


Link to post
Share on other sites
10 hours ago, Kiwi Chris said:

I either need to get my import to strip leading spaces

using trim() is considered good practice whenever you deal with user input or import/export stuff, so yes: definitely make it a habit.

  • Like 1

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...