</select>
</div>
<div class="col-md-6" ng-class="{'bg-success': working.price !== undefined}">
- <input class="form-control" ng-disabled="!defaults.attributes.price" ng-model="working.price" type="number"/>
+ <input class="form-control" ng-disabled="!defaults.attributes.price" string-to-number precision="2" ng-model="working.price" type="number" step="0.01"/>
</div>
</div>
</select>
</div>
<div class="col-md-6" ng-class="{'bg-success': working.cost !== undefined}">
- <input class="form-control" ng-disabled="!defaults.attributes.cost" ng-model="working.cost" type="number"/>
+ <input class="form-control" ng-disabled="!defaults.attributes.cost" string-to-number precision="2" ng-model="working.cost" type="number" step="0.01"/>
</div>
</div>
</div>
</div>
<div class="col-md-6" ng-class="{'bg-success': working.deposit_amount !== undefined}">
- <input class="form-control" ng-disabled="!defaults.attributes.deposit_amount" ng-model="working.deposit_amount" type="number"/>
+ <input class="form-control" ng-disabled="!defaults.attributes.deposit_amount" string-to-number precision="2" ng-model="working.deposit_amount" type="number" step="0.01"/>
</div>
</div>
return service;
}])
+.directive('stringToNumber', function() {
+ return {
+ require: 'ngModel',
+ link: function(scope, element, attrs, ngModel) {
+ var precision = attrs.precision || 0;
+ ngModel.$parsers.push(function(value) {
+ return value;
+ });
+
+ function updateDisplay() {
+ var value = parseFloat(ngModel.$viewValue);
+ if ( isNaN(value) ) { return; }
+ element.val(value.toFixed(precision));
+ }
+
+ ngModel.$formatters.push(function(value) {
+ return parseFloat(value);
+ });
+
+ ngModel.$viewChangeListeners.push(updateDisplay);
+
+ ngModel.$render = function() {
+ updateDisplay();
+ }
+ }
+ };
+})
+
.directive("egVolCopyEdit", function () {
return {
restrict: 'E',