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

Search supposed to support numeric input? #2968

Closed
bitwombat opened this issue Apr 11, 2018 · 16 comments
Closed

Search supposed to support numeric input? #2968

bitwombat opened this issue Apr 11, 2018 · 16 comments

Comments

@bitwombat
Copy link

Hi,

Using v1.8.2, I have options that have numbers in them (eg. WHS301) and I find I can search for 'W' (or 'WH' or 'WHS'), but not '301'.

Is this meant to be? I had a thumb through the source but couldn't find what I was looking for.

I will create a testcase if this is not the intended behavior.

@tjschuck
Copy link
Member

You need to set the search_contains option to true (it's false by default). Documentation here.

@bitwombat
Copy link
Author

Thanks, that works, sorry it was a RTFM.

But wait... without that option, my searches do start from the middle of the word. It's specifically the numbers that are different:

image

Now I type a 3:

image

Something undocumented?

@tjschuck
Copy link
Member

@bitwombat No worries — glad to help!

As for the behavior you're seeing, that is strange! What browser, browser version, OS, and OS version are you using? And what version of Chosen? If not the latest version, does it still happen on the latest version?

Can you link to a publicly accessible page (or a Fiddle) that shows the issue?

@bitwombat
Copy link
Author

Will put together a testcase and fill out the questions on your contributing guidelines...

@tjschuck
Copy link
Member

@bitwombat Thanks, that would be great!

@bitwombat
Copy link
Author

Good news - jsFiddle knows about v1.8.5. Bad news, the link they use to cloudflare is 404.

This is 404
https://cdnjs.cloudflare.com/ajax/libs/chosen/1.8.5/chosen.jquery.min.js

and this
https://cdnjs.cloudflare.com/ajax/libs/chosen/1.8.4/chosen.jquery.min.js

but not this
https://cdnjs.cloudflare.com/ajax/libs/chosen/1.8.3/chosen.jquery.min.js

Want me to make a new issue for that?

@tjschuck
Copy link
Member

@adunkman ^ Know anything about how those files end up there? Both of the versions you pushed today seem to not be currently working.

@adunkman
Copy link
Contributor

Negatory… I assume a cron or something? But they seem to be working now!

@bitwombat
Copy link
Author

Alright, here we go:

Steps to reproduce

Go to
current v1.8.5

Type "WHS" then "3" (no quotes)

Compare with:

v 1.6.1

I include both because they act differently. v1.6.1 highlights the first occurrence of "WHS", which makes the lack of matching of "WHS3" odd.

However 1.8.5 highlights the occurrence of WHS in the description part of the option, which if that means it's not seeing the first part, would make sense that "WHS3" doesn't match anything.

Expected behavior

Chosen should not be matching the middle of the string without the search_contains option.

With the current behavior which seems to be matching within the string anyway, Chosen should match BSBWHS302

Actual behavior

No results are found.

Environment

  • Chosen Version:
    Shown in links above.

  • jQuery or Prototype Version:
    See source.

  • Browser and Version:
    Firefox 59.0.2 (linux)
    Chrome 65.0.3325.181 (linux)

  • OS and Version:
    Linux

@tjschuck tjschuck reopened this Apr 16, 2018
@tjschuck
Copy link
Member

@bitwombat It looks like you're still missing the search_contains option. You need to set the search_contains option to true (it's false by default).

If you add search_contains: true in your example JS here http://bitwombat.com.au/chosen/js/init.js everything works as you'd expect:

screenshot showing correct functionality

Options documentation.

Please let me know if I'm misunderstanding your issue, though!

@bitwombat
Copy link
Author

Correct. The issue is really that when the option is false, Chosen sort of, sometimes, matches things in the middle.

@tjschuck
Copy link
Member

tjschuck commented Apr 17, 2018

@bitwombat That's actually the correct, fixed behavior. When you have the option set to false, it's matching on the middle one because that's the first instance that actually matches with that rule — it doesn't match the first WHS because it's inside of a word, and it does match the second WHS (correctly) because that's the occurrence that starts on a word boundary.

PR #2692 is what fixed this behavior, and that fix was included in version 1.7.0.

@MB-Tom
Copy link

MB-Tom commented Nov 30, 2018

What if you must enter numbers only?

I am using a list of ALL numeric characters such as:

0400000010469004
0400000010468342
0400000010468949
0400000010469059
0400000010469106
0400000010468214
0400000010468932
0400000010469058
0400000010468438
0400000010467091
0400000010468973
0400000010469063
0400000010468341
0400000010468672
0400000010469081
0400000010468723
0400000010468081
...

Which gives:

list

I would like the users to only have to enter a partial of the number (eg. 68814) and get a result set, instead I get:

results

Chosen v1.8.7 / JQuery 3.3.1 / IE11 (Windows 10 Enterprise)

@tjschuck
Copy link
Member

@MB-VictoryRider See my answer above here:
#2968 (comment)

You need to set the search_contains option.

@MB-Tom
Copy link

MB-Tom commented Dec 3, 2018

I did set it:
<script type="text/javascript"> $(".chosen-select").chosen({ search_contains: true }); </script>

if you try searching for 468 it doesn't find anything.
Sorry, pasting the entire code in as code didn't work. so I've attached an abbreviated file.

test_aspx.txt

@NarjisHasan
Copy link

Did anyone find the solution to the problem: all numerical options not searching from middle even with search_contains set to true ?

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

5 participants