aboutsummaryrefslogtreecommitdiffstats
path: root/src/formatters.js
diff options
context:
space:
mode:
authorMisko Hevery2010-05-10 20:24:20 -0700
committerMisko Hevery2010-05-10 20:24:20 -0700
commit5dda723185a9037b7e92828d32430c21838ee216 (patch)
tree15e12ff20e020bb524d704bc7e0d2f8d1f6f1b40 /src/formatters.js
parentf5027cc375cf29d8a78679297d9f6bdca9567eb7 (diff)
downloadangular.js-5dda723185a9037b7e92828d32430c21838ee216.tar.bz2
improved handling of text fields when formater fails to prevent clobering of field
Diffstat (limited to 'src/formatters.js')
-rw-r--r--src/formatters.js23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/formatters.js b/src/formatters.js
index ee63c1a5..40462cf3 100644
--- a/src/formatters.js
+++ b/src/formatters.js
@@ -1,11 +1,20 @@
-function formater(format, parse) {return {'format':format, 'parse':parse || format};}
-function toString(obj) {return isDefined(obj) ? "" + obj : obj;}
+function formatter(format, parse) {return {'format':format, 'parse':parse || format};}
+function toString(obj) {return (isDefined(obj) && obj !== null) ? "" + obj : obj;}
+
+var NUMBER = /^\s*[-+]?\d*(\.\d*)?\s*$/;
+
extend(angularFormatter, {
- 'noop':formater(identity, identity),
- 'boolean':formater(toString, toBoolean),
- 'number':formater(toString, function(obj){return 1*obj;}),
+ 'noop':formatter(identity, identity),
+ 'boolean':formatter(toString, toBoolean),
+ 'number':formatter(toString,
+ function(obj){
+ if (isString(obj) && NUMBER.exec(obj)) {
+ return obj ? 1*obj : null;
+ }
+ throw "Not a number";
+ }),
- 'list':formater(
+ 'list':formatter(
function(obj) { return obj ? obj.join(", ") : obj; },
function(value) {
var list = [];
@@ -17,7 +26,7 @@ extend(angularFormatter, {
}
),
- 'trim':formater(
+ 'trim':formatter(
function(obj) { return obj ? trim("" + obj) : ""; }
)
});