mirror of
https://github.com/openMF/community-app.git
synced 2026-02-06 09:37:29 +00:00
Minor decimal point issue solved.
This commit is contained in:
parent
1c9bdb95c4
commit
443345bbed
@ -1,55 +1,68 @@
|
||||
(function (module) {
|
||||
mifosX.directives = _.extend(module, {
|
||||
NumberFormatDirective: function ($filter) {
|
||||
NumberFormatDirective: function ($filter, $locale) {
|
||||
return {
|
||||
replace: false,
|
||||
//restrict: "A",
|
||||
require: 'ngModel',
|
||||
link: function (scope, element, attrs, modelCtrl) {
|
||||
var filter = $filter('number');
|
||||
var filter = $filter('number');
|
||||
|
||||
function number(value, fractionLength) {
|
||||
return filter(value, fractionLength);
|
||||
return filter(value, fractionLength);
|
||||
}
|
||||
modelCtrl.$formatters.push(number);
|
||||
|
||||
function initialNumber(value) {
|
||||
var stringValue = modelCtrl.$modelValue + '';
|
||||
var index = stringValue.indexOf($locale.NUMBER_FORMATS.DECIMAL_SEP);
|
||||
var fraction = stringValue.substring(index + 1);
|
||||
var fractionLength = fraction.length;
|
||||
var initialnumber = $filter('number')(modelCtrl.$modelValue,fractionLength);
|
||||
return initialnumber;
|
||||
}
|
||||
|
||||
modelCtrl.$formatters.push(initialNumber);
|
||||
|
||||
modelCtrl.$parsers.push(function (stringValue) {
|
||||
var index = stringValue.indexOf($locale.NUMBER_FORMATS.DECIMAL_SEP),
|
||||
decimal,
|
||||
fraction,
|
||||
fractionLength;
|
||||
if (index >= 0) {
|
||||
decimal = stringValue.substring(0, index);
|
||||
fraction = stringValue.substring(index + 1);
|
||||
if(index!=stringValue.length-1)
|
||||
fractionLength = fraction.length;
|
||||
else
|
||||
fractionLength = 0;
|
||||
} else {
|
||||
decimal = stringValue;
|
||||
fraction = '';
|
||||
}
|
||||
decimal = decimal.replace(/[^0-9]/g, '');
|
||||
fraction = fraction.replace(/[^0-9]/g, '');
|
||||
var result = +(decimal + '.' + fraction);
|
||||
if (result !== modelCtrl.$modelValue) {
|
||||
scope.$evalAsync(function () {
|
||||
modelCtrl.$viewValue = number(modelCtrl.$modelValue, fractionLength);
|
||||
modelCtrl.$render();
|
||||
});
|
||||
}
|
||||
return result;
|
||||
if(stringValue){
|
||||
var index = stringValue.indexOf($locale.NUMBER_FORMATS.DECIMAL_SEP),
|
||||
decimal,
|
||||
fraction,
|
||||
fractionLength;
|
||||
if (index >= 0) {
|
||||
decimal = stringValue.substring(0, index);
|
||||
fraction = stringValue.substring(index + 1);
|
||||
if(index!=stringValue.length-1)
|
||||
fractionLength = fraction.length;
|
||||
else
|
||||
fractionLength = 0;
|
||||
} else {
|
||||
decimal = stringValue;
|
||||
fraction = '';
|
||||
}
|
||||
decimal = decimal.replace(/[^0-9]/g, '');
|
||||
fraction = fraction.replace(/[^0-9]/g, '');
|
||||
var result = +(decimal + '.' + fraction);
|
||||
if (result !== modelCtrl.$modelValue) {
|
||||
scope.$evalAsync(function () {
|
||||
modelCtrl.$viewValue = number(modelCtrl.$modelValue, fractionLength);
|
||||
modelCtrl.$render();
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
});
|
||||
|
||||
scope.$on('$localeChangeSuccess', function (event, localeId) {
|
||||
modelCtrl.$viewValue = $filter('number')(modelCtrl.$modelValue);
|
||||
modelCtrl.$render();
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
}(mifosX.directives || {}));
|
||||
mifosX.ng.application.directive("numberFormat", ['$filter', mifosX.directives.NumberFormatDirective]).run(function ($log) {
|
||||
mifosX.ng.application.directive("numberFormat", ['$filter', '$locale', mifosX.directives.NumberFormatDirective]).run(function ($log) {
|
||||
$log.info("NumberFormatDirective initialized");
|
||||
});
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
{"name": "Français", "code": "fr"},
|
||||
{"name": "Español", "code": "es"},
|
||||
{"name": "Português", "code": "pt"},
|
||||
{"name": "中文", "code": "zh_cn"},
|
||||
{"name": "中文", "code": "zh_CN"},
|
||||
{"name": "हिंदी", "code": "hi"},
|
||||
{"name": "ქართული", "code": "ka"}
|
||||
]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user