The views add dialog filter search does not work as expected, it searches the label element instead of the title element.
When adding fields, filters, etc., in Views I am unable to use the string 'date' in the Search field to narrow down the available options. This is because the string of searchable text is derived from the input label, which as far as I can tell always contains the word "update".
To reproduce:
1. Edit a view,
2. in the Fields area, click "Add",
3. type "date" into the Search field.
The list should be filtered to only "date"-related options, but instead nothing happens. (I initially thought the keyword search wasn't working at all.)
This problem doesn't exist in 7.x.
Proposed solution: Formulate the searchText from the <td class="title">
element, which does not have "Update " prepended, instead of <label>
.
I'll upload a patch in a moment.
Comment | File | Size | Author |
---|---|---|---|
#43 | drupal-views_ui-filtering_options-2846428-43.patch | 6.52 KB | Anonymous (not verified) |
#38 | interdiff-37-38.txt | 7.57 KB | Anonymous (not verified) |
#38 | drupal-views_ui-filtering_options-2846428-38.patch | 6.54 KB | Anonymous (not verified) |
#37 | drupal-views_ui-filtering_options-2846428-36.patch | 8.92 KB | michielnugter |
#37 | interdiff.txt | 4.33 KB | michielnugter |
Comments
Comment #2
othermachines CreditAttribution: othermachines commentedComment #3
othermachines CreditAttribution: othermachines commentedHere's a better one.
Comment #5
Lendude@othermachines nice find! Manually tested this and you are spot on.
Fix makes sense, we need some Javascript tests for this though. There is some basic search setup in #2754985: [backport] Add JavaScript test coverage for adding an exposed filter in Views UI but that tries to do more and it's postponed on the extra things it's trying to do. So maybe some dedicated tests for the handler filtering would be great here.
Comment #6
othermachines CreditAttribution: othermachines commentedHi, @Lendude. Sort of funny, huh? I'm actually surprised it wasn't noticed before, since... well, date fields.
I just had a quick look at the patch in #2754985-11: [backport] Add JavaScript test coverage for adding an exposed filter in Views UI and it looks like the basics are covered there. Are you suggesting pulling out the filter-related stuff into a simpler test?
This particular issue is a bit quirky and having eliminated the cause I don't think it warrants adding a special test case, do you? A string is a string - at least 99% of the time, anyway. :-/ Only thing I might suggest adding is to assert that description text is being searched so we know both elements are being correctly targeted and contain expected text.
Comment #7
LendudeWell yeah, looking at it now, combining the handler search testing with the exposed filter test makes little sense. The search needs its own dedicated test, and in that test I think its fine to add a search for the 'date' string and see that it currently fails to give the expected result.
Comment #8
dagmarMarked #2847555: Searching for fields in views_ui doesn't work as expected as duplicated from this issue.
So I have a different problem, that is not fixed by this issue. If you search for ID, the results are not really representative.
This new patch sort the handlers table by string length so if you type a few letters of a word, you will see first the shorter strings and will have more chance to find what you are looking for first.
Comment #9
droplet CreditAttribution: droplet commentedI think it isn't duplicated. This one is bug fixing. Another one is search result improvement. #8 improvement may take a longer time to discuss in details.
I also created an issue to seek a common workaround for all these search fields.
#2846950: Narrow down Instant Search Field result in CORE
Patch #3 looks good. It's ready to go.
Comment #10
John Cook CreditAttribution: John Cook commentedI've tested patch #3 and #8 against 8.4.x.
Patch 3
The results for #3 are as follows:
Before patch:
After patch:
This works as described.
Patch 8
Patch #8 also performs a fix for this problem but it also has some other side effects.
Before patch:
After patch:
As you can see the order of the fields has change.
Therefore I would suggest moving patch #8 into Narrow down Instant Search Field result in CORE and commit #3 to fix the immediate problem.
Setting to RTBC for patch #3 and hiding #8 from display.
Comment #11
LendudeAs discussed in #5-#7, this still needs tests before we can RTBC it.
On reading up on this I agree with @droplet that this is a bug fix and #8 is an improvement, sorry @dagmar for implying that they might be the same thing. An improvement very much worth doing though!
Comment #12
othermachines CreditAttribution: othermachines commentedI'll work on a test this week.
Comment #13
othermachines CreditAttribution: othermachines commentedAt the moment I'm having trouble running tests locally so not sure what will happen here (fingers crossed).
Comment #17
othermachines CreditAttribution: othermachines commentedWith all variables defined this time.
Comment #18
othermachines CreditAttribution: othermachines commentedOops. Initial test should fail because result is all rows, not zero rows. New test also checks if returned rows are less than total rows.
Comment #20
Lendude@othermachines nice!
This should be updated to use the new preferred assertions that were added in #2837676: Provide a better way to validate all javascript activity is completed
Comment #21
Anonymous (not verified) CreditAttribution: Anonymous commented#18: looks nice for me too! +1 for #20 and few remarks
A good practice is to manage only classes
format_string deprecated, and we haven't reason use it here.
similarly
Comment #22
droplet CreditAttribution: droplet commentedAn assertion to ensure it has the same number of "Updated" & rows at the beginning is required.
Comment #23
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commentedSmall cleanup
- Used the new wait... methods.
- Added doxygen
- Added coverage for filterVisibleElements() by first checking the count before filtering. That covers @droplet's input right?
- Removed assertion messages as they're discouraged and fixed the deprecation.
- Changed deprecated assertFieldByName() implementation.
Comment #24
othermachines CreditAttribution: othermachines commentedThanks for comments. Came by to roll another patch but I see it's been done.
Comment #25
droplet CreditAttribution: droplet commentedThanks @michielnugter! It's very close but it isn't what I wanted.
The reason we ran into the current problem is the word "Update" was added to label at some point. I bet that was an improvement of Accessibility. And that can be "Update" and "Add" in the future code changes. Or a checked box changed to "Checked Label" rather than "Update Label"..etc. At that point, it has potential to bring the bug back.
To prevent this happen again, we must check the word "Update" that match the rows at the beginning instead.
Comment #26
othermachines CreditAttribution: othermachines commentedIn response to #25 just wanted to note that fix proposed in #3 means the search string is no longer derived from label element so future changes there for reasons of accessibility (or whatever) wouldn't cause the issue to reemerge.
Small nitpick Re #23:
I don't think it's necessary to run this again after filtering.
Comment #27
Anonymous (not verified) CreditAttribution: Anonymous commentedI will try to explain #25 with an example again (be loyal to my English):
"Update" prefix pointless, let's use "Check"
.title
tolabel
again.@droplet offers great idea to prevent this problem, because it very easy to implement. Although, of course, it does not give an absolute guarantee. It would be great to find for test a way to set unique words in
.title
and.description
tags and testing search by them. But it is much more difficult, and perhaps not worth wasting time.It would be great add check "Update" count near with search by 'date'. And documentation this.
Comment #28
LendudeOk, so that sounds like we should make a custom global field handler in a test module, give that a distinct title and description and test for that.
Comment #29
droplet CreditAttribution: droplet commentedThanks @vaplas.
Instead of rebuilding a search system in the test case, another little tweak we could do:
1. Additional to above test.
2. Use JS (or any simple way) to change a label in Row A to "UniqueSearchWordWithoutSpaces"
3. Use JS to change a .title in Row B to "UniqueSearchWordWithoutSpaces"
4. Perform a search of "UniqueSearchWordWithoutSpaces"
5. Check if the result is Row B and only 1 result
Comment #30
othermachines CreditAttribution: othermachines commented@vaplas - Very clear, thanks! I did suggest a broader approach in #6 (testing that elements are being targeted correctly). I'm honestly not sure about that now, though.
Is testing implementation (not just expected behaviour) a good idea? #29 would work to flag a very specific code change, but it assumes that change will always be bad. As soon as someone finds a *good* reason to omit the .title element from search functionality the test will not only fail, it will become obsolete - even though the behaviour itself might work perfectly.
I'm not suggesting that's the wrong way to do it - just trying to get a better understanding of the end goal so I can be more useful.
Comment #31
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commentedI looked at the JavaScript and it is hardcoded to look at the .title and .description tags. Because it is hardcoded a test should cover it, we want to cover each line of code in a test.
If the HTML is changed without updating the JavaScript this test will catch that and indicate the JavaScript (and this test) will also need an update.
So actually to make it complete, we need to inspect the HTML as part of the test and search on both title and description seperately. To make it complete we should use a custom global field to have better control over the text we want to search for.
Comment #32
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commentedWorking on something, will finish it tomorrow and post it then.
Comment #33
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commentedOk, new version.
I added a test module that adds two fields with a unique and searchable title and description.
The title and description are tested seperately now. I think the test now covers everything in JavaScript and I don't think any deeper inspection makes the test better. If the HTML is changed without the JavaScript this test will fail thus catching the broken functionality.
Comment #34
LendudeHa! Sneaky, providing a title and description without an actual working plugin. I like!
Only this permission is needed. The other three can go.
'Assert all rows are visible before filtering'. Otherwise we need to specify what 'the count' is equal to.
This gives excellent base coverage. We are now missing the 'date' search though. I would expect an additional test where we search for 'date' and find neither test fields (so something that would fail without the fix).
Comment #35
Anonymous (not verified) CreditAttribution: Anonymous commented@michielnugter good works! But unfortunately, we still have the problem. If we change the
.title
tolabel
, this test pass too :( BecauseWhat about
hook_form_alter()
? And what about set special word for label and testing that we not search by this too?Also bit remarks:
Double check. Maybe we can use:
Maybe use only:
$this->assertCount(1, $visible_rows);
Comment #36
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commentedUpdated test:
- Permissions fixed
- Reintroduced the label filter test using the form alter @vaplas suggested, thanks for that!
- Cleaned up double assertions and comments. @vaplas: The waitFor() doesn't fail if the assertion never passes, a recheck after the waitFor is required because of that.
Important warning though, I'm experiencing random failures on this test, the same as in #2832672. We need to fix this before we can commit this patch.. I'll postpone this one once it fails/passes.
Comment #37
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commentedComment #38
Anonymous (not verified) CreditAttribution: Anonymous commented#37 looks great for me! Now we have two controllable fields, hence we can not depend from other items. This simplifies the test, no?
I meant, that
waitFor()
returnTRUE
if success (orFALSE
if not). We can use this fact. But +1 to useisVisible()
by readability reason.Review #38 patch:
Looks like forgotten comment. And maybe the addition would be better than a replacement, because we save words from title in this field.
Just reduction to a one view.
Comment #39
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commentedNice cleanup! You're completely right about the overcomplicated way of testing now that we have 2 fields to check on..
Commented line, whoops.. Sorry about that.
Still we have to wait with RTBC untill the related issue is fixed I think..
Comment #40
droplet CreditAttribution: droplet commentedIt's the right time to go I think.
Comment #41
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commentedIgnore my note on the related bug and no-commit: The random fail only occurs if you update the PhantomJS Driver. It's safe to commit this, without the driver upgrade I had no random fails..
Comment #42
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commentedUpdated issue title and added small generic comment on the description to indicate the fix/test is not aimed at fixing the date search specifically but at searching the correct element.
Comment #43
Anonymous (not verified) CreditAttribution: Anonymous commentedreroll by instruction.
Comment #44
alexpottCommitted and pushed f974370 to 8.4.x and c78d01c to 8.3.x. Thanks!
Fixed unused on commit.