Fixes validation of input form. Improved error message

This commit is contained in:
Gustavo Cortez 2014-06-12 11:09:18 -03:00
commit a76de35bb0
2 changed files with 10 additions and 7 deletions

View file

@ -649,9 +649,10 @@
<label for="amount">Amount
<small ng-hide="!sendForm.amount.$pristine">required</small>
<small class="is-valid" ng-show="!sendForm.amount.$invalid && !sendForm.amount.$pristine">valid!</small>
<small class="has-error" ng-show="sendForm.amount.$invalid && !sendForm.amount.$pristine">
not valid.</small>
<small ng-show="notEnoughAmount">{{notEnoughAmount}}</small>
<small class="has-error" ng-show="sendForm.amount.$invalid && !sendForm.amount.$pristine && !notEnoughAmount">
not valid
</small>
<small ng-show="notEnoughAmount">Insufficient funds!</small>
</label>
<div class="small-9 columns">
<input type="number" id="amount" ng-disabled="loading"

View file

@ -39,16 +39,18 @@ angular.module('copayApp.directives')
])
.directive('enoughAmount', ['$rootScope',
function($rootScope) {
var bitcore = require('bitcore');
var feeSat = bitcore.TransactionBuilder.FEE_PER_1000B_SAT;
return {
require: 'ngModel',
link: function(scope, element, attrs, ctrl) {
var val = function(value) {
var vStr = new String(value);
var vNum = Number(vStr);
var availableBalanceNum = ($rootScope.availableBalance * bitcore.util.COIN).toFixed(0);
var vNum = Number((value * bitcore.util.COIN).toFixed(0)) + feeSat;
if (typeof vNum == "number" && vNum > 0) {
if ($rootScope.availableBalance <= vNum) {
if (availableBalanceNum < vNum) {
ctrl.$setValidity('enoughAmount', false);
scope.notEnoughAmount = 'Insufficient funds!';
scope.notEnoughAmount = true;
} else {
ctrl.$setValidity('enoughAmount', true);
scope.notEnoughAmount = null;