Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disappearing Suggestions #1

Open
nickpoulos opened this issue Nov 9, 2018 · 5 comments
Open

Disappearing Suggestions #1

nickpoulos opened this issue Nov 9, 2018 · 5 comments

Comments

@nickpoulos
Copy link

Hey guys, great package. I was using Spatie's own Nova field that uses their tag manager under the hood, but did not offer suggestions, so I switched to this one. However I am having a small bug.

The suggestions keep disappearing anytime there is a second or third keystroke. When I type in 'R' the Restaurants suggestions pops up, but then when I type in the rest like 'Res' it disappears. Anybody else experiencing this?

@ipalaus
Copy link
Member

ipalaus commented Nov 10, 2018

Hi,

Suggestions do work on both packages, Spatie's and our own too. I'd suggest you to check the responses the APIs are returning in the Chrome Dev Tools. Or you could also just write a dump in this file https://github.com/palauaandsons/nova-tags-field/blob/master/src/Http/Controllers/TagsFieldController.php#L21 to debug what's happening.

Let me know if that helps.

@nickpoulos
Copy link
Author

nickpoulos commented Nov 10, 2018

I know Spatie's underlying tag package offers suggestions, but I did not see that on their Nova tag field package? Maybe I did not look well enough.

Anyway, so the bug is - you are automatically lowercasing ONLY the input, which never allows it to match tags that start with a capital. Please see line 21 of TagsFieldController.php.

php $query->where('name', 'like', '%' . strtolower($request['filter']['containing']) . '%');

Updating the like operator to 'ilike' for case-insensitive fixes the issue I am seeing.

php $query->where('name', 'ilike', '%' . strtolower($request['filter']['containing']) . '%');

I would make a PR and all that but since it is a one-char fix might be better if you do? Although you may want to remove the strtolower altogether now, I believe adding the 'i' should accomplish what strtolower was attempting to do. Thanks though!

@nickpoulos
Copy link
Author

nickpoulos commented Nov 10, 2018

So the bug is, you are automatically lowercasing ONLY the input, which never allows it to match tags that start with a capital. Please see line 21 of TagsFieldController.php.

php $query->where('name', 'like', '%' . strtolower($request['filter']['containing']) . '%');

Updating the like operator to 'ilike' for case-insensitive should fix your bug. Thanks though!

php $query->where('name', 'ilike', '%' . strtolower($request['filter']['containing']) . '%');

@ipalaus
Copy link
Member

ipalaus commented Nov 11, 2018

This will return you both Restaurant and restaurant, just tried.

select * from tags where name like '%res%'

Which database driver are you using? ILIKE it's not a MySQL specific term

@nickpoulos
Copy link
Author

nickpoulos commented Nov 11, 2018

Ahhhhh, ok ok, I think I know what the issue is. Yes that is true, I am using Postgres, I forgot MySQL does not have an iLIKE. Besides the lack of iLike operator, the driver should not matter otherwise. Generally speaking, case sensitivity is defined by the column/table/database collation settings.

Ex UTF8_GENERAL_CI you would not need to do any lower/case insensitive tricks, it is done automatically, just like your example.

That could very well be the discrepancy in the results we are seeing. Because I get an empty result set when I run

select * from tags where name like '%res%'

In order to not have any of these issues, and to be database driver agnostic, maybe it would be best to change the query to something like:

$query->whereRaw('LOWER(`name`) LIKE ? ',['%' . trim(strtolower($request['filter']['containing'])) .'%']);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants