Input set value problems


#1

Hi,

I’ve a search bar with a button for clear the search like this:

   <div class="bar bar-header item-input-inset">
       <form name="search_form" class="item-input-wrapper" ng-submit="clearSearch()">
          <label class="item-input-wrapper">
             <i class="icon ion-ios7-search placeholder-icon"></i>
             <input id="searchKey" type="search" placeholder="Recherche par enseigne, nom ou numéro..." ng-model="searchKey" autocorrect="off" >
             <button class="button-clear icon ion-close-circled" ng-click="clearSearch()"></button>
          </label>
       </form>
       <button class="button button-clear" ng-click="search(searchKey)">Rechercher</button>
    </div>

And in my controller i’ve my function clearSearch():

$scope.clearSearch = function() {
    $scope.searchKey= "";
    $scope.getHostsWarning();
};

But the input value never changed if i write text in the input…

Anyone can help me?

Thanks!


#2

I found a solution i do this:

<form name="search_form" class="item-input-wrapper" ng-submit="clearSearch(); searchKey=''">

#3

Another solution that might work.

In your controller wrap searchKey inside another object (say formdata):

.controller('Controller', function($scope, $state) {

        $scope.formdata = [];
        $scope.formdata.searchKey = "";

...
}

…and then in HTML:

<input id="searchKey" type="search" placeholder="Recherche par enseigne, nom ou numéro..." ng-model="formdata.searchKey" autocorrect="off" >

I’m not 100% sure why this fixes it but it did for me when I had an identical problem.