Accent problem and special characters leave bold autocomplete term

Asked

Viewed 326 times

1

I have this script that does a search using the Jquery autocomplete.

$( function($) {
    $.ui.autocomplete.prototype._renderItem = function (ul, item) {        
        var t = String(item.value).replace(
        new RegExp(this.term, "gi"),
        "<strong>$&</strong>");
        return $("<li></li>")
        .data("item.autocomplete", item)
        .append("<a>" + t + "</a>")
        .appendTo(ul);
    };              
    
    $( "#p" ).autocomplete({
        source: "php/search_palavras.php?id_cidade=<?php echo $id_cidade; ?>",
        minLength: 2,
                        
        select: function( event, ui ) {
            // Set autocomplete element to display the label
            this.value = ui.item.label;
                    
            // Store value in hidden field
            $('#hidden_p').val(ui.item.id);

            // Prevent default behaviour
            return false;                   
        }
    });
                
    $( "#p" ).click(function() {
        $('#hidden_p').val(0);
        $('#p').val('');
    });         
}); 

Almost everything is perfect. The only problem I’m having, I don’t know if it’s PHP or Jquery, but if I start a search with "aco", the answers come:

Butchers

Sacolões Hortifrutigrangeiros

Central Tourist Information Offices

Wholesale and Manufacture of Sacos plastics

I tried in every way, but I can’t highlight the "steel" or "action" that have cedilla and accents. It would be possible to highlight these items as well?

  • You are just sending the text to your server, which should treat the results that should return, so I believe that your problem is neither with PHP nor jQuery, but with database. Ex.: Mysql collation utf8_general_ci, whether it is set so it makes no distinction between accented or not.

  • In the table I do the research, the field is utf8_general_ci. On the PHP search page, I put a mysqli_set_charset($config,"utf8"); not to have problems with accentuation, but even so, does not highlight the accentuation.

  • To help: https://alistapart.com/article/accent-folding-for-auto-complete

1 answer

0


I’m not sure if this is what you want, but I have a solution. Use the function htmlspecialchars() in data output.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.