Skip to content
Browse files

updated number validator to not throw exception on null content

  • Loading branch information...
1 parent 47c94a2 commit 807e3682e562eb2871a809a6a4d3d04cc20b2737 @onkis onkis committed with etgryphon Apr 27, 2010
Showing with 3 additions and 1 deletion.
  1. +3 −1 frameworks/foundation/validators/number.js
View
4 frameworks/foundation/validators/number.js
@@ -51,7 +51,7 @@ SC.Validator.Number = SC.Validator.extend(
} else if (this.get('places') > 0) {
value = parseFloat(value) ;
} else {
- if(value.length==1 && value.match(/-/)) value = null;
+ if(value.length===1 && value.match(/-/)) value = null;
else {
result = parseInt(value,0) ;
if(isNaN(result)){
@@ -84,9 +84,11 @@ SC.Validator.Number = SC.Validator.extend(
Allow only numbers, dashes, period, and commas
*/
validateKeyDown: function(form, field, charStr) {
+ if(!charStr) charStr = "";
var text = field.$input().val();
if (!text) text='';
text+=charStr;
+
if(this.get('places')===0){
if(charStr.length===0) return true;
else return text.match(/^[\-{0,1}]?[0-9,\0]*/)[0]===text;

0 comments on commit 807e368

Please sign in to comment.
Something went wrong with that request. Please try again.