In this codepen :
http://codepen.io/anon/pen/EjKqbW
I'm attempting to reset the form elements when user clicks "Reset". So div elements f1,f2,f3
should be hidden and searchText
box cleared. But the reset button is not firing. I think reason is that multiple submit buttons are not allowed as part of AngularJS form ?
How can set the form elements as specified when "Reset" clicked ?
src :
<html>
<head>
<title>AngularJS test</title>
</head>
<body ng-app ng-controller="TestCtrl">
<form ng-submit="submit()">
<div style="display:none" id="notFound">Not Found</div>
<div style="display:none" id="f1"></div>
<div style="display:none" id="f2"></div>
<div style="display:none" id="f3"></div>
<input id="searchText" type=text/>
<input type="submit" ng-click="submit" value="Submit">
<input type="submit" ng-click="reset" value="Reset">
</form>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.min.js"></script>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
</body>
</html>
function TestCtrl($scope , $http) {
$scope.reset = function() {
$("#f1").css('display' , 'none');
$("#f2").css('display' , 'none');
$("#f3").css('display' , 'none');
$("#searchText").text('');
}
$scope.submit = function() {
$http.get('').
success(function(data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
$("#f1").text('test');
$("#f1").css('display' , 'block');
$("#f2").text('test');
$("#f2").css('display' , 'block');
$("#f3").text('test');
$("#f3").css('display' , 'block');
}).
error(function(data, status, headers, config) {
$("#notFound").css('display' , 'block');
// called asynchronously if an error occurs
// or server returns response with an error status.
});
}
}