BUG 6284 Changing mask validator direction for text fields.

This commit is contained in:
Enrique Ponce De Leon
2011-04-12 16:09:55 -04:00
parent 729cc04733
commit bf6f76c366

View File

@@ -303,14 +303,19 @@ function G_DropDown( form, element, name )
} }
G_DropDown.prototype=new G_Field(); G_DropDown.prototype=new G_Field();
function G_Text( form, element, name ) function G_Text( form, element, name, type )
{ {
var me=this; var me=this;
var mType = 'text';
this.parent = G_Field; this.parent = G_Field;
this.parent( form, element, name ); this.parent( form, element, name );
if (element) { if (element) {
this.prev = element.value; this.prev = element.value;
} }
if (type){
//alert('Type: ' + type);
mType = type;
}
this.validate = 'Any'; this.validate = 'Any';
this.mask=''; this.mask='';
this.required=false; this.required=false;
@@ -458,7 +463,11 @@ function G_Text( form, element, name )
startPos++; startPos++;
var newValue2; var newValue2;
if (mType !== 'text'){
newValue2 = G.toMask(newValue, me.mask, startPos); newValue2 = G.toMask(newValue, me.mask, startPos);
}else{
newValue2 = G.toMask(newValue, me.mask, startPos, 'normal');
}
me.element.value = newValue2.result; me.element.value = newValue2.result;
me.setSelectionRange(newValue2.cursor, newValue2.cursor); me.setSelectionRange(newValue2.cursor, newValue2.cursor);
@@ -782,7 +791,7 @@ function G_Percentage( form, element, name )
{ {
var me=this; var me=this;
this.parent = G_Text; this.parent = G_Text;
this.parent( form, element, name ); this.parent( form, element, name, 'percentage');
this.validate = 'Int'; this.validate = 'Int';
this.mask= '###.##'; this.mask= '###.##';
} }
@@ -792,7 +801,7 @@ function G_Currency( form, element, name )
{ {
var me=this; var me=this;
this.parent = G_Text; this.parent = G_Text;
this.parent( form, element, name ); this.parent( form, element, name, 'currency');
this.validate = 'Int'; this.validate = 'Int';
this.mask= '_###,###,###,###,###;###,###,###,###,###.00'; this.mask= '_###,###,###,###,###;###,###,###,###,###.00';
} }
@@ -1102,7 +1111,31 @@ function G()
} }
//Apply a mask to a number //Apply a mask to a number
function _ApplyMask(num, mask, cursor){ function _ApplyMask(num, mask, cursor, dir){
if (dir){
var osize = num.length;
_out = '';
num = _checkNumber(num, mask);
num = _getOnlyNumbers(num,'');
if (num.length == 0) return {result: '', cursor: 0};
iNum = num;
iMask = mask;
eMask = iMask.split('');
eNum = iNum.split('');
for (e=0; e < eMask.length; e++){
switch(eMask[e]){
case '#': case '0':
if (eNum.length > 0){
key = eNum.shift();
_out += key;
}
break;
default:
_out += eMask[e];
break;
}
}
}else{
var __DECIMAL_SEP = '.'; var __DECIMAL_SEP = '.';
var osize = num.length; var osize = num.length;
num = _checkNumber(num, mask); num = _checkNumber(num, mask);
@@ -1216,6 +1249,7 @@ function G()
} }
} }
_out = invertir(_out); _out = invertir(_out);
}
if (_out.length > osize){ if (_out.length > osize){
cursor = cursor + (_out.length - osize); cursor = cursor + (_out.length - osize);
} }
@@ -1226,7 +1260,7 @@ function G()
} }
//Manage Multiple Mask and Integer/Real Number restrictions //Manage Multiple Mask and Integer/Real Number restrictions
this.toMask = function(num, mask, cursor){ this.toMask = function(num, mask, cursor, direction){
if (mask==='') return { if (mask==='') return {
'result': new String(num), 'result': new String(num),
'cursor': cursor 'cursor': cursor
@@ -1235,7 +1269,7 @@ function G()
var result = []; var result = [];
var subMasks=mask.split(';'); var subMasks=mask.split(';');
for(var r=0; r<subMasks.length; r++) { for(var r=0; r<subMasks.length; r++) {
result[r]=_ApplyMask(num, subMasks[r], cursor); result[r]=_ApplyMask(num, subMasks[r], cursor, direction);
} }
var betterResult=0; var betterResult=0;
for(r=1; r<subMasks.length; r++) { for(r=1; r<subMasks.length; r++) {