Case insensitive isn't functioning for "Autocomplete for predefined suggestions", for "Autocomplete for existing field data" it works as expected.

Comments

bleen’s picture

Status: Active » Needs review
StatusFileSize
new739 bytes

I havent really had time to test this, but i think this'll do it.

bleen’s picture

StatusFileSize
new1.17 KB

oops ... wrong version of the patch

bleen’s picture

StatusFileSize
new1.17 KB

now this is just embarrassing ... ignore #1 & #2

cees.vanegmond’s picture

bleen18, sorry #3 doesn't work as expected. I tried to look into it but my drupal module experience is not sufficient to do this task.

side note: I saw that exposed filters in views also supplies the autocomplete widget, I tried to select the autocomplete widget but it doesn't seem to function at all.

bleen’s picture

Status: Needs review » Closed (works as designed)

cees.vanegmond: Can you please send me an example of the "predefined suggestions" you are entering and then examples of what you are typing and what results you are getting vs. expecting.

Here is a quick screencast of what i am seeing which I believe is the correct behavior: http://screencast.com/t/hD900irbER8d

If you can give me an example of how this isn't working Ill take another look. In the mean time I'm committing the patch in #3 since its cleaner code and marking "works as designed"

cees.vanegmond’s picture

Well, for example the following list, the days of the week:
Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday (on separate lines in the form field)
I would like to have te option of case insensitive input, when an user types "mon", Monday should occur and be able to get selected.
This case insensitive setting can be set in the edit tab next to the widget tab.
---
Case sensitive
o Disabled
o Enabled
Case-insensitive queries are implemented using the LOWER() function in combination with the LIKE operator. Note that MySQL might ignore case sensitivity depending on the collation used in your database definition (see Internationalization and Localization chapter in the MySQL manual). If you need case insensitive checks, it is recommended (for performance reasons) to use a case insensitive collation as well (such as utf8_general_ci), rather than disabling the case sensitive option here.
---
By disabling case sensitive I expect the behaviour as I describe above.
Note: Node reference and Term reference have the same behaviour

sportel’s picture

Version: 7.x-1.x-dev » 7.x-1.0-beta1

Hi,

I've got the same problem. I'm using a predefined list of languages to choose from, al beginning with a capital. When entering "ned", nothing shows, while when entering "Ned", "Nederlands" shows in the list. I'm using the latest advised D7 version. Hope you can help.

Thanks,

Mike.

bleen’s picture

Assigned: Unassigned » bleen
Status: Closed (works as designed) » Needs review
StatusFileSize
new1.98 KB

I finally took another look at this and I think I found the problem. This patch should take care of it... (and make the code a bit easier to read).

Desi Raaj’s picture

I can confirm this fixes the problem, thank you so much :)

bleen’s picture

Status: Needs review » Fixed

I'll take that as an RTBC....

I've committed this to the latest dev version of 7.x-1.x (http://drupalcode.org/project/autocomplete_widgets.git/commit/7621c46)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

arbel’s picture

Hi,

I'm using the latest dev and tried beta 2 and it doesn't seem to work.

when searchiing for:

berlin
I get no results.

when searching for Berlin
I get multiple results.

I don't completely understand the sentence under the setting for case sensitive....

Thanks

Idan

cees.vanegmond’s picture

Status: Closed (fixed) » Active

Finaly I took time to look into this item since it's not working.

First of all on line 133 and 177 of 'autocomplete_widgets.common.inc' $case_sensitive is retrived from $field['widget']['autocomplete_case'], this should be $field['widget']['settings']['autocomplete_case']

Next item is that the use of empty() gives strange behaviour, if Case Sensitive is disabled (=0) then empty() returns true. If Case Sensitive is enabled (=1) then empty() returns false. I don't see the point.

Furthermore I made the following changes to function _autocomplete_widgets_get_options_suggested() to fit my expectations for the function:

function _autocomplete_widgets_get_options_suggested($field, $string = '', $match = 'contains', $keys = NULL, $limit = NULL) {
  $case_sensitive = $field['widget']['settings']['autocomplete_case'];

  $options = explode("\n", $field['widget']['settings']['suggested_values']);
  $options = array_map('trim', $options);
  $options = array_filter($options, 'strlen');

  switch ($match) {
    case 'contains':
    case 'starts_with':
      $matched_options = array();
      
      if (!$case_sensitive) {
        foreach ($options as $option) {
          if ($match == 'contains' && stripos($option, $string) !== FALSE) {
            $matched_options[] = $option;
          }
          elseif ($match == 'starts_with' && stripos($option, $string) === 0) {
            $matched_options[] = $option;
          }
        }
      } else {
        foreach ($options as $option) {
          if ($match == 'contains' && strpos($option, $string) !== FALSE) {
            $matched_options[] = $option;
          }
          elseif ($match == 'starts_with' && strpos($option, $string) === 0) {
            $matched_options[] = $option;
          }
        }
      }
      $options = $matched_options;
      break;
    case 'equals':
      if (in_array($string, $options, TRUE)) {
        $options = array($string);
      }
      break;

  }

  return $options;
}

This returns the case sensitive value in the 'Suggeset values list' even the search has be done case insensitive.

I think that the 'equal case' should also be changed in the same manner, this has not been implemented in code above.

bleen’s picture

cees.vanegmond:

  • please confirm that you are still seeing this error when using 7.x-1.0-beta2 or 7.x-1.x-dev. The fix from #8 was not part of beta1
  • can you provide some exact steps to reproduce this problem using dev or beta2
  • can you please provide a patch (against dev) with your suggested changes in #13 so they can be properly evaluated.
cees.vanegmond’s picture

  • 7.x-1.0-beta2
  • I've use an field with the following properties:
    Text processing: Plain text
    Autocomplete matching: Contains
    Case sensitive: Disabled
    Filter HTML: Disabled
    Suggeset values list: (states of The Netherlands)
    Drenthe
    Flevoland
    Friesland
    Gelderland
    Groningen
    Limburg
    Noord-Brabant
    Noord-Holland
    Overijssel
    Utrecht
    Zeeland
    Zuid-Holland

    When I use an exposed filter in a view, or just entering data in a new or existing node, I would expect the module to return for 'hol' both Noord-Holland and Zuid-Holland. This is not the case with 7.x-1.0-beta2. The reason why I'm expecting this behaviour is that this is the same for taxonomies for example.

  • I would love to but I've never applied a patch nor how to do so
bleen’s picture

To create a patch, please see the instructions here: http://drupal.org/patch

Its not very hard, I promise

valve79@gmail.com’s picture

Installed the RC1 and the Upper/lower case issue still exists.

Looked through the patches.

Which patch should i use ?
Or can some one point me in right direction to change the right chunk of code ?

TimTheEnchanter’s picture

@valve79

If you are using the option "Autocomplete for existing field data and some node titles" there is a conditional statement that hides the field setting for Case Sensitivity. Commenting out the IF statement worked for me

Line 31 of autocomplete_widgets.admin.inc (7.x-1.x-dev)

//if ($widget['type'] != 'autocomplete_widgets_node_reference') {
    $form['autocomplete_case'] = array(
      '#type' => 'radios',
      '#title' => t('Case sensitive'),
      '#default_value' => $settings['autocomplete_case'],
      '#options' => array(0 => t('Disabled'), 1 => t('Enabled')),
    );
  //}