MCSI
MCSI

Reputation: 2894

Issue with chosen harvesthq's jquery plugin

I'm using this plugin

http://harvesthq.github.com/chosen/

and I have an specific problem when I search some options with blanks. for example I have an option tha is "Antigua y barbuda" if I type :

  1. Antigua y barbuda -> ok
  2. Antigua y -> ok
  3. barbuda -> ok
  4. y -> ok
  5. y barbuda -> fail

it only fails when I start writing not the first word (only in cases that has blanks)

Regex:

regex = new RegExp(regexAnchor + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');

Upvotes: 0

Views: 1919

Answers (4)

Alex
Alex

Reputation: 51

For Joomla developers with similar issues:

JHtml::_('formbehavior.chosen', 'select', null, array('search_contains' => true));

Upvotes: 1

user2233038
user2233038

Reputation:

You don't need to remove \s just set search_contains: true

$(".chzn-select").chosen({search_contains: true});

Upvotes: 2

MCSI
MCSI

Reputation: 2894

Solved it removing "\s"

zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#]/g, "\\$&"), 'i');

Upvotes: 1

Grzegorz Kaczan
Grzegorz Kaczan

Reputation: 21676

This is might be a Chosen problem. Try using Select2 plugin, which originate from Chosen and its much better. Plus it allows custom matcher function so you can resolve your problem manually.

Upvotes: 4

Related Questions