Select2 not displaying html entities correctly

darren

Member
Hello,

The transition to using Select2 instead of jquery I believe was a good move, seems faster and a little easier. however, i am running into an issue.

Whenever i want to search something using the autocomplete feature, items that have the & or other signs are not displayed correctly. instead the character is displayed as & as in "Jim & Bob" not "Jim & Bob". Another issue is that the separators no longer work.

with jquery autocomplete the columns for each table that was searched were separated by a '-' for example, if I search for a record and the autocomplete returns results from multiple columns such as " First Name - Last Name - Address" then searching bob would return something like "Bob - Newell - 44 Adam Street" and 30 other matching results. I would also be able to further refine my search by typing in "Bob - newell" which would limit the result to rows with first name 'bob' and last name 'newell'.

unfortunately I am unable to do this anymore and can only search one column at all. I dont know if this is a limitation of Select2 or if it is related to the html encoding error or not.

Help would be appreciated.

You are using DaDaBIK version 8.2-Lerici pro, installed on Dec 19, 2017 (installation code: 130575a022f599edc0), the latest version of DaDaBIK is 8.2-Lerici released on Dec 19, 2017

You are runnning the last release of DaDaBIK

PHP Version: 7.1.12-1+ubuntu16.04.1+deb.sury.org+1

mysql version: 5.7.20-0ubuntu0.16.04.1

Web server: Apache/2.4.18 (Ubuntu)

Client: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36
 

eugenio

Administrator
Staff member
Hello,
you are right, the first issue you mentioned is definitely a bug that affects lookup fields when user-friendly searchable is set to yes AND ajax loading is ON. Thanks for having reported it.

A quick fix: in index.php search for these lines

$json_answer['results'][$cnt]['id']=htmlspecialchars($primary_key_value);
$json_answer['results'][$cnt]['text']=htmlspecialchars($linked_fields_value);

and remove htmlspecialchars

$json_answer['results'][$cnt]['id']=($primary_key_value);
$json_answer['results'][$cnt]['text']=($linked_fields_value);

I will go into the second part of your post later.

Best,
 

eugenio

Administrator
Staff member
Hello,
about the second part of your message, you are also right: the lookup menu search works "for column" when you enable the ajax loading. Here is a patch to get the same behaviour you get without ajax loading: in /include/business_logic.php, look for the function build_dropdown_query; in the function comment what you have from

$linked_field_filter_where = '';

to (including)

$linked_field_filter_where = substr_custom($linked_field_filter_where, 0, -4); // delete the last " OR "

and add this code afterwards:


if ($dbms_type === 'sqlite' || $dbms_type === 'postgres'){
$linked_field_filter_where = "(";
$concatenation_chars_number = 13;
}
else{
$linked_field_filter_where = "concat(";
$concatenation_chars_number = 9;
}

for ($j=0; $j<$count_temp; $j++) {
if ($dbms_type === 'sqlite' || $dbms_type === 'postgres'){
$linked_field_filter_where .= $quote.$linked_fields_ar[$j].$quote." || ' - ' || ";
}
else{
$linked_field_filter_where .= $quote.$linked_fields_ar[$j].$quote.", ' - ', ";
}
}

$linked_field_filter_where = substr_custom($linked_field_filter_where, 0, -$concatenation_chars_number); // delete the last ", ' - ', "

if ($dbms_type === 'sqlite' || $dbms_type === 'postgres'){
$linked_field_filter_where .= ") LIKE ('%' || :linked_field_filter || '%')";
}
else{
$linked_field_filter_where .= ") LIKE concat('%', :linked_field_filter, '%')";
}

Let me know if it works correctly.

Best,
 

darren

Member
your patch seems to work

I was getting a strange result of "the results could not be loaded" when searching for a record for a while before and after your code, however, the problem seems to have gone away, hopefully it stays that way

Thank you very much, I appreciate the assistance.
 

eugenio

Administrator
Staff member
You are welcome, thanks to you for the detailed feedback, it was very helpful.

I don't think the "the results could not be loaded" message is related to the other issues but keep me updated if it happens again.

Best,
 
Top