From 98fa7eae404818607532ecf08e8b7857c2cb7050 Mon Sep 17 00:00:00 2001 From: Jared Tabor Date: Mon, 1 Dec 2014 22:10:34 -0500 Subject: [PATCH] Float directive I changed the float directive last week and now i'm reverting it back. The change i made didn't account for neagative numbers so i'm reverting back --- awx/ui/static/lib/ansible/directives.js | 30 +++++-------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/awx/ui/static/lib/ansible/directives.js b/awx/ui/static/lib/ansible/directives.js index 18e0a5ff0b..76d7799cd9 100644 --- a/awx/ui/static/lib/ansible/directives.js +++ b/awx/ui/static/lib/ansible/directives.js @@ -183,19 +183,14 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job }]) .directive('smartFloat', function() { - var FLOAT_REGEXP_1 = /^\$?\d+(.\d{3})*(\,\d*)?$/, //Numbers like: 1.123,56 - FLOAT_REGEXP_2 = /^\$?\d+(,\d{3})*(\.\d*)?$/; //Numbers like: 1,123.56 + var FLOAT_REGEXP = /^\-?\d+((\.|\,)\d+)?$/; return { - restrict: 'A', require: 'ngModel', - link: function (scope, elm, attrs, ctrl) { - ctrl.$parsers.unshift(function (viewValue) { - if (FLOAT_REGEXP_1.test(Number(viewValue))) { + link: function(scope, elm, attrs, ctrl) { + ctrl.$parsers.unshift(function(viewValue) { + if (FLOAT_REGEXP.test(viewValue)) { ctrl.$setValidity('float', true); - return parseFloat(viewValue.replace('.', '').replace(',', '.')); - } else if (FLOAT_REGEXP_2.test(Number(viewValue))) { - ctrl.$setValidity('float', true); - return parseFloat(viewValue.replace(',', '')); + return parseFloat(viewValue.replace(',', '.')); } else { ctrl.$setValidity('float', false); return undefined; @@ -203,21 +198,6 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job }); } }; - // var FLOAT_REGEXP = /^\-?\d+((\.|\,)\d+)?$/; - // return { - // require: 'ngModel', - // link: function(scope, elm, attrs, ctrl) { - // ctrl.$parsers.unshift(function(viewValue) { - // if (FLOAT_REGEXP.test(viewValue)) { - // ctrl.$setValidity('float', true); - // return parseFloat(viewValue.replace(',', '.')); - // } else { - // ctrl.$setValidity('float', false); - // return undefined; - // } - // }); - // } - // }; }) // integer Validate that input is of type integer. Taken from Angular developer