vsGoogleAutocomplete icon indicating copy to clipboard operation
vsGoogleAutocomplete copied to clipboard

Impossible to empty the input text

Open fdonzello opened this issue 9 years ago • 6 comments

Hi,

if you search for a city and then you get the result, when you try to empty the input text the last result will be set to the input (the model).

So:

  1. search for 'Rome'
  2. you get 'Rome, Italy'
  3. empty the input
  4. you get 'Rome, Italy' again when the input loses the focus

fdonzello avatar Dec 10 '15 11:12 fdonzello

Hi @wideawake,

Currently behavior is you should click enter button to apply changes. I think it may cause issues on mobile devices.

vskosp avatar Dec 21 '15 08:12 vskosp

is this issue solved ? i'm also facing same issue(empty the input)

sanjsdev avatar Dec 26 '15 07:12 sanjsdev

Will be solved asap

vskosp avatar Dec 30 '15 14:12 vskosp

i've had the same problem and fixed it forcing the clear of autocomplete model: the 'autocomplete' parameter is the input where autocomplete is located;


var input = angular.element(document.querySelectorAll('input[name=autocomplete_location]'));
clearAutoCompleteModel(getAutoCompleteObj(input[0]));

function getAutoCompleteObj(element) {
    for (var key in element) {
        if (key.indexOf('jQuery') == 0 && element[key].$vsGoogleAutocompleteController)
            return element[key];
    }
}

function clearAutoCompleteModel(autocomplete) {
            let auto = autocomplete;
            let modelCtrl = auto.$ngModelController;
            let viewValue = modelCtrl.$viewValue == "" ? '' : modelCtrl.$viewValue;
            if (!viewValue) $scope.jobPosition = new JobPosition();
            $timeout(function () {
                $scope.$apply(function () {
                    modelCtrl.$setViewValue(viewValue);
                    modelCtrl.$render();
                });
            });
        };

this make me able to clean input after the selection of one place inside autocomplete. i think it's easy to fix it directly inside the code. Obviusly there'll be an issue with the required validation, that doesn't accept any empty value. Now i'm not able to give time to this issue, but i would like to make a PR.

matteoPhre avatar Dec 06 '16 14:12 matteoPhre

What line should I put this in? because I'm getting a Cannot read property '$ngModelController' of undefined in my console.

Markj89 avatar Jan 27 '17 19:01 Markj89

Was this problem ever fixed? It still persists today @vskosp

wbaizer avatar Aug 10 '18 16:08 wbaizer