Browse files

Fixed bug at reverse mask when the precision was bigger than 3, thx to

  • Loading branch information...
1 parent 70f4264 commit 03dab03bf31b3b53fc75c53fed9053d387861afe @nagaozen nagaozen committed with Jan 15, 2012
Showing with 31 additions and 13 deletions.
  1. +7 −7 Source/Meio.Mask.Extras.js
  2. +5 −5 Source/Meio.Mask.Reverse.js
  3. +19 −1 Specs/moo.meio.mask.js
View
14 Source/Meio.Mask.Extras.js
@@ -21,11 +21,11 @@ provides: [Meio.Mask.Extras]
(function(){
var meiomask = 'meiomask';
-
+
var upperCamelize = function(str){
return str.camelCase().capitalize();
};
-
+
var getClassOptions = function(a1, a2, opts){
var klass;
if (typeOf(a1) == 'string'){
@@ -43,9 +43,9 @@ provides: [Meio.Mask.Extras]
}
return {klass: klass, options: opts || {}};
};
-
+
var executeFunction = function(functionName, args){
- var co = getClassOptions.apply(null, args);
+ var co = getClassOptions.apply(null, args);
return new co.klass(co.options)[functionName](this);
};
@@ -79,15 +79,15 @@ provides: [Meio.Mask.Extras]
return this;
}
};
-
+
Element.Properties[meiomask + ':value'] = {
// sets the value but first it applyes the mask (if theres any)
set: function(value){
var mask = this.retrieve(meiomask);
if (mask) value = mask.mask(value);
return this.set('value', value);
},
-
+
// gets the unmasked value
get: function(){
var mask = this.retrieve(meiomask);
@@ -101,5 +101,5 @@ provides: [Meio.Mask.Extras]
return this.set(meiomask, [mask, type, options]);
}
});
-
+
})();
View
10 Source/Meio.Mask.Reverse.js
@@ -36,16 +36,16 @@ Meio.Mask.Reverse = new Class({
initialize: function(options){
this.parent(options);
var thousandsChar = this.options.thousands,
- escapedThousandsChars = thousandsChar.escapeRegExp(),
+ escapedThousandsChar = thousandsChar.escapeRegExp(),
escapedDecimalChar = this.options.decimal.escapeRegExp();
this.maxlength = this.options.maxLength;
- this.reThousands = /(\d+)(\d{3})/;
+ this.reThousands = new RegExp('^([^\\D'+ escapedThousandsChar +']+)(\\d{3})');
this.reRemoveLeadingZeros = /^0+(.*)$/;
this.reDecimalNumber = /^\d$/;
this.thousandsReplaceStr = '$1' + thousandsChar + '$2';
- this.reThousandsReplace = new RegExp(escapedThousandsChars, 'g');
- this.reCleanup = new RegExp('[' + escapedThousandsChars + escapedDecimalChar + ']', 'g');
- this.reRemoveNonNumbers = new RegExp('[^\\d' + escapedThousandsChars + escapedDecimalChar + ']', 'g');
+ this.reThousandsReplace = new RegExp(escapedThousandsChar, 'g');
+ this.reCleanup = new RegExp('[' + escapedThousandsChar + escapedDecimalChar + ']', 'g');
+ this.reRemoveNonNumbers = new RegExp('[^\\d' + escapedThousandsChar + escapedDecimalChar + ']', 'g');
},
link: function(element){
View
20 Specs/moo.meio.mask.js
@@ -52,11 +52,29 @@ test('should mask a string with the reverse.integer mask', function(){
test('should mask a string with the reverse.decimal mask', function(){
equals('345678.728'.meiomask('reverse.decimal'), '345.678,73');
});
-
+
test('should unmask the passed string', function(){
equals('12/12/2000'.meiounmask('Fixed', 'Date'), '12122000');
});
test('should unmask the passed string to a float number', function(){
equals('R$ 123,12'.meiounmask('reverse.reais'), 123.12);
});
+
+test('should apply a precision: 5 mask to the 0 string', function(){
+ equals('0'.meiomask('Reverse', 'Decimal', { precision: 5 }), '0,00000');
+});
+
+test('should apply a precision: 5 mask to the 1 string', function(){
+ equals('1'.meiomask('Reverse', 'Decimal', { precision: 5 }), '1,00000');
+});
+
+test('should apply a precision: 5 mask to the 1000 string', function(){
+ equals('1000'.meiomask('Reverse', 'Decimal', { precision: 5 }), '1.000,00000');
+});
+
+test('should apply a precision: 5 mask to the 0.001 string', function(){
+ equals('0.001'.meiomask('Reverse', 'Decimal', { precision: 5 }), '0,00100');
+});
+
+

0 comments on commit 03dab03

Please sign in to comment.