-1

I have very generic javascript code for autocomplete. Everything works fine, but when You type:

Manner

You will have result:

Manner

Männer

In database i have words with special letters, but in case "manner" i dont want to show word with letter "ä" - as this dont fit to result to me.

How can i ignore results like this ?

Thank You for any advice.

The code:

$(document).ready(function () {
    if ($('#tags').length <= 0) {
        return;
    }
    var $project = $('#tags');
    $project.autocomplete({
        minLength: 2,

        source: function (request, response) {
            $.ajax({
                dataType: "json",
                type: 'post',
                cache: false,
                data: {term: request.term},
                url: '/ajax/',

                success: function (data) {

                        response($.map(data, function (item) {
                            return {
                                label: item.Cities__zip,
                                value: item.Cities__zip
                            }
                        }));

                }
            });
        },

    });
});
Marek Brzeziński
  • 325
  • 1
  • 3
  • 13

1 Answers1

0

This looks to like something that would be better to handled server rather than client side. But if you want to do it in the ajax call you could do something like this, which utilizes a regular expression to match non-English characters, and filters those items out:

$(document).ready(function () {
    if ($('#tags').length <= 0) {
        return;
    }
    var $project = $('#tags');
    $project.autocomplete({
        minLength: 2,
        source: function (request, response) {
            $.ajax({
                dataType: "json",
                type: 'post',
                cache: false,
                data: {term: request.term},
                url: '/ajax/',
                success: function (data) {
                    response($.map(data, function (item) {
                    return (/[^\u0000-\u007F]+/).test(item.Cities__zip) ? null : 
                    {
                        label: item.Cities__zip,
                        value: item.Cities__zip
                    }
                }));

                }
            });
        },

    });
});
Community
  • 1
  • 1
Gabby Paolucci
  • 887
  • 8
  • 23