Answer the question
In order to leave comments, you need to log in
AngularJS vs browser form autocomplete?
I can't figure out how to deal with browser autocompletion.
There is a form:
<form>
<input ng-model="user.username" name="username" type="text" placeholder="Электронная почта" />
<input ng-model="user.password" name="password" type="password" placeholder="Пароль" value="" />
</form>
this.submit = function () {
$http.post(action, $scope.user)
.success(
function (data) {
if (data.result == "success") {
window.location = data.url;
} else {
$scope.login.errors = data.message;
}
})
.error(function () {
$scope.login.errors = "Непредвиденная ошибка, попробуйте позже";
})
};
Answer the question
In order to leave comments, you need to log in
This is an open ticket - https://github.com/angular/angular.js/issues/1460
In general, all solutions come down to a directive that checks the input value with a timeout and updates the model. Look at the ticket there - a bunch of implementations, for example:
app.directive("watchAutofill", [
'$timeout',
function ($timeout) {
var INTERVAL_MS = 500;
return {
require: 'ngModel',
link: function (scope, element, attrs, ngModel) {
var timer;
function startTimer() {
timer = $timeout(function () {
var value = element.val();
if (value && ngModel.$viewValue !== value) {
ngModel.$setViewValue(value);
}
startTimer();
}, INTERVAL_MS);
}
scope.$on('$destroy', function () {
$timeout.cancel(timer);
});
startTimer();
}
};
}
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question