Fixes decimal inputs

This commit is contained in:
Gustavo Maximiliano Cortez 2015-08-07 11:23:32 -03:00
commit 93028b9be0
No known key found for this signature in database
GPG key ID: 15EDAD8D9F2EB1AF
3 changed files with 17 additions and 11 deletions

View file

@ -87,22 +87,22 @@ angular.module('copayApp.directives')
])
.directive('validAmount', ['configService', '$locale',
function(configService, locale) {
var formats = locale.NUMBER_FORMATS;
return {
require: 'ngModel',
link: function(scope, element, attrs, ctrl) {
var val = function(value) {
if (value) value = value.replace(/,/g, '.');
var settings = configService.getSync().wallet.settings;
var vNum = Number((value * settings.unitToSatoshi).toFixed(0));
if (typeof value == 'undefined') {
if (typeof value == 'undefined' || value == 0) {
ctrl.$pristine = true;
}
if (typeof vNum == "number" && vNum > 0) {
var decimals = Number(settings.unitDecimals);
var sep_index = ('' + value).indexOf(formats.DECIMAL_SEP);
var sep_index = ('' + value).indexOf('.');
var str_value = ('' + value).substring(sep_index + 1);
if (sep_index > 0 && str_value.length > decimals) {
ctrl.$setValidity('validAmount', false);