amount validation

This commit is contained in:
2016-04-11 17:28:56 +02:00
parent 46e718bb85
commit f628531c09
2 changed files with 11 additions and 6 deletions
+7 -3
View File
@@ -18,8 +18,6 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
}; };
if (typeof $scope.categories !== 'undefined') { if (typeof $scope.categories !== 'undefined') {
// TODO default-Kategorie sollte per Account einstellbar sein
console.log('DID IT!');
$scope.transaction.category = $scope.categories[0]; $scope.transaction.category = $scope.categories[0];
} }
@@ -60,12 +58,18 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
$scope.postTransaction = function() { $scope.postTransaction = function() {
var amount = $scope.transaction.amount.replace(',', '.');
if (amount.charAt(0) !== '+' && amount.charAt(0) !== '-') {
amount = '-' + amount;
}
// via Resource (might be moved into a service) // via Resource (might be moved into a service)
var Transaction = $resource('/transactions'); var Transaction = $resource('/transactions');
var newTransaction = new Transaction({ var newTransaction = new Transaction({
"account" : $scope.account._links.self.href, "account" : $scope.account._links.self.href,
"amount" : $scope.transaction.amount, "amount" : amount,
"date" : $scope.transaction.date, "date" : $scope.transaction.date,
"description" : $scope.transaction.description, "description" : $scope.transaction.description,
"category" : $scope.transaction.category._links.self.href, "category" : $scope.transaction.category._links.self.href,
@@ -2,10 +2,11 @@
<div> <div>
<div><select ng-model='account' ng-change='refreshList()' ng-options="account.name for account in accounts track by account.id"></select></div> <div><select ng-model='account' ng-change='refreshList()' ng-options="account.name for account in accounts track by account.id"></select></div>
<div> <div>
<form role="form" ng-submit="postTransaction()"> <form name="form" ng-submit="postTransaction()">
<div> <div>
Betrag: <input ng-model='transaction.amount' type='number' step='0.01' /> Betrag: <input name="amount" ng-model='transaction.amount' type='text' required ng-pattern="/^[+-]?(?:\d+(?:[\.,]\d{0,2})?|[\.,]\d{1,2})$/" />
</div> </div>
<span ng-show="form.amount.$error.pattern"">The value is not a valid value!</span>
<div> <div>
Kategorie: <select ng-model='transaction.category' size='1' Kategorie: <select ng-model='transaction.category' size='1'
ng-options="category.name for category in categories track by category._links.self.href"> ng-options="category.name for category in categories track by category._links.self.href">
@@ -18,7 +19,7 @@
Notiz: <input ng-model='transaction.description' type='text' size='20' /> Notiz: <input ng-model='transaction.description' type='text' size='20' />
</div> </div>
<div> <div>
<input type="submit" /> <input type="submit" ng-disabled="form.amount.$error.pattern" />
</div> </div>
</form> </form>