Kiwi Chris Posted September 28, 2019 Share Posted September 28, 2019 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 More sharing options...
wbmnfktr Posted September 28, 2019 Share Posted September 28, 2019 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? 1 Link to comment Share on other sites More sharing options...
dragan Posted September 28, 2019 Share Posted September 28, 2019 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. 1 Link to comment Share on other sites More sharing options...
Kiwi Chris Posted September 29, 2019 Author Share Posted September 29, 2019 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 More sharing options...
dragan Posted September 30, 2019 Share Posted September 30, 2019 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. 1 Link to comment Share on other sites More sharing options...
Robin S Posted October 1, 2019 Share Posted October 1, 2019 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: After: Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now