mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
11 lines
448 B
CoffeeScript
11 lines
448 B
CoffeeScript
angular.module("ofn.admin").directive "ofnDecimal", ->
|
|
require: "ngModel"
|
|
link: (scope, element, attrs, ngModel) ->
|
|
numRegExp = /^\d+(\.\d+)?$/
|
|
element.bind "blur", ->
|
|
scope.$apply ngModel.$setViewValue(ngModel.$modelValue)
|
|
ngModel.$render()
|
|
|
|
ngModel.$parsers.push (viewValue) ->
|
|
return viewValue + ".0" if viewValue.indexOf(".") == -1 if angular.isString(viewValue) and numRegExp.test(viewValue)
|
|
viewValue |