A
A
ART42020-05-13 12:26:13
JavaScript
ART4, 2020-05-13 12:26:13

Filtering text in input by list?

Good afternoon, who can come across.
There is an input

<input ng-model="search" id='search' autocomplete="off" onfocus="this.removeAttribute('readonly')" onkeyup="limitInput( 'en', this );" class="cities_value form_input placeholder_focus" name="city" type="text" value="{$city|escape}" data-language="form_city" maxlength="30">

When I start writing it iterates over the array of cities starting with the first letter.
5ebbbdfb2369476075543.jpeg

The question arose with an edge for me something:
And how to make it so that when typing in the input, 100% of the text from the array comes across.

So that the person in the input field could not enter another value from the list.

Let's say:
Cities of the Russian Federation
  1. Entered a value in the input "M", he brought me Moscow, Murmansk, etc.
  2. Then I entered the second value and it became "Mo", he brought me out of the proposed ones only Moscow.
  3. But then if I enter a new third value D and I get "Mod", but there is no such city, the letter D immediately disappeared

Comparing value in input and value in list
function inArray(value, array) {
                var valCity = $('#search').val();
                var valCity_text = valCity.charAt(0).toUpperCase() + valCity.substr(1);
                
                for (var i = 0; i < arrCity.length; i++) {
                    if (valCity_text === arrCity[i]) {
                        //$('.result_city').html('<div class="good_text">Правильно</div>');
                    }  else {
                        //$('.result_city').html('<div class="fail_text">Не правильно</div>');
                        
                    }
                    return false;
                }
                
            }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question