ngChange handler called, on submit, for blank type="number" fields, when they haven't changed #17181
Description
I suppose this doesn't meet the LTS definition of a critical bug.
But I am going to file it here in case it is - at the very least - helpful to other people.
I spent a lot of time tracking down this issue. It's confusing and non-obvious why this would happen.
I'm submitting a ...
- regression from 1.7.0
- security issue
- issue caused by a new browser version
- other
Current behavior:
If you initialise, or clear a <input type="number">
field to blank (ie ""
). It's ng-change
handler will always be called on submit. Even if it has not been changed.
Expected / new behavior:
Change handler does not get called.
Minimal reproduction of the problem with instructions:
An example
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
<div ng-app="app">
<div ng-controller="MainCtrl">
<form ng-submit="submit()">
<input type="number" ng-model="form.testNumber" ng-change="changed()"/>
<button type="submit">Submit</button>
</form>
</div>
</div>
var app = angular.module("app", []);
app.controller("MainCtrl", function ($scope) {
$scope.form = {
testNumber: ""
};
$scope.changed = function () {
console.log("changed");
};
$scope.submit = function () {
console.log("submitted");
};
});
see: http://jsfiddle.net/6qxrygzm/1/
Click the submit button in the demo. The console will log the message "changed" even though the field is untouched from its initialised value.
AngularJS version: 1.8.2
Browser: all | Chrome 98.0.4758.102 | Firefox 97.0.1 (64-bit)
Anything else: