diff --git a/gulliver/js/form/core/form.js b/gulliver/js/form/core/form.js index 5fc5fa1df..c55151987 100755 --- a/gulliver/js/form/core/form.js +++ b/gulliver/js/form/core/form.js @@ -3042,14 +3042,17 @@ function sumaformu(ee,fma,mask){ theelemts=objectsWithFormula[i_elements].theElements; nfk = ''; - //to replace the field for the value and to evaluate the formula + //to replace the field for the value and to evaluate the formula + var symbol = mask.replace(/[0-9.#,-_\s]/g,''); for (var i=0; i < theelemts.length; i++){ if(!isnumberk(theelemts[i])){//alert(getField(theelemts[i]).name); - val = (getField(theelemts[i]).value == '')? 0 : getField(theelemts[i]).value; - formula=formula.replace(theelemts[i],val); + val = (getField(theelemts[i]).value == '')? 0 : getField(theelemts[i]).value.replace(/[$a-zA-Z\s]/g,''); + formula=formula.replace(theelemts[i],val); } } - + if (isnumberk(getField(theelemts['0']).value)) + getField(theelemts['0']).value = symbol+ ' '+getField(theelemts['0']).value; + var rstop=eval(formula); if(mask!=''){ putmask(rstop,mask,ans); @@ -3117,6 +3120,8 @@ function putmask(numb,mask,ans){ numDecimal=maskDecimal[1].length; ans.value=numb.toFixed(numDecimal); + var symbol = mask.replace(/[0-9.#,-_\s]/g,''); + if (isnumberk(ans.value)) ans.value = symbol+' '+ans.value; return; var nnum='',i=0,j=0; //we get the number of digits diff --git a/gulliver/js/grid/core/grid.js b/gulliver/js/grid/core/grid.js index 574f63780..ef9014e7d 100755 --- a/gulliver/js/grid/core/grid.js +++ b/gulliver/js/grid/core/grid.js @@ -303,7 +303,12 @@ var G_Grid = function(oForm, sGridName){ parentGG.removeChild(aObjects[n]); parentGG.appendChild(oNewOBJ); }else{ - aObjects[n].value = defaultValue; + if ((attributes.gridtype) && (attributes.gridtype=='currency')) { + var attributesCurrency = elementAttributesNS(aObjects[0], ''); + aObjects[n].value = attributesCurrency.value.replace(/[.,0-9\s]/g,'');; + } + else + aObjects[n].value = defaultValue; } } break; @@ -769,7 +774,8 @@ var G_Grid = function(oForm, sGridName){ nnName= this.aElements[k].name.split(']['); if (aAux[2] == nnName[2] && j <= (this.oGrid.rows.length-2)){ oAux=this.getElementByName(j, nnName[2]); - if ( (oAux != null) && (oAux.value().trim() != '') ) { + var oAux2 = oAux.value().replace(/[$|a-zA-Z\s]/g,''); + if ( (oAux != null) && (oAux.value().trim() != '') && (oAux2)) { fTotal += parseFloat(G.getValue(oAux.value())); } j++; @@ -877,7 +883,7 @@ var G_Grid = function(oForm, sGridName){ for (i = 0; i < aFields.length; i++) { if (!isNumber(aFields[i])) { oAux = this.getElementByName(aAux[1], aFields[i]); - sAux = sAux.replace(new RegExp(aFields[i], "g"), "parseFloat(G.cleanMask(this.getElementByName(" + aAux[1] + ", '" + aFields[i] + "').value() || 0, '" + (oAux.sMask ? oAux.sMask : '') + sAux = sAux.replace(new RegExp(aFields[i], "g"), "parseFloat(G.cleanMask(this.getElementByName(" + aAux[1] + ", '" + aFields[i] + "').value().replace(/[$|a-zA-Z\s]/g,'') || 0, '" + (oAux.sMask ? oAux.sMask : '') + "').result.replace(/,/g, ''))"); eval("if (!document.getElementById('" + aAux[0] + '][' + aAux[1] + '][' + aFields[i] + "]')) { oContinue = false; }"); } @@ -901,8 +907,15 @@ var G_Grid = function(oForm, sGridName){ }else{ maskToPut=0; } + var symbol = document.getElementById(aAux[0]+']['+ aAux[1] + '][' + oField.sFieldName + ']').value.replace(/[0-9.\s]/g,''); + var bkp = document.getElementById(aAux[0] + '][' + aAux[1] + '][' + oField.sFieldName + ']').value; eval("document.getElementById('" + aAux[0] + '][' + aAux[1] + '][' + oField.sFieldName + "]').value = (" + sAux + ').toFixed('+maskToPut+');'); - //eval("document.getElementById('" + aAux[0] + '][' + aAux[1] + '][' + oField.sFieldName + "]').value = (" + sAux + ').toFixed(2);'); + + if (document.getElementById(aAux[0] + '][' + aAux[1] + '][' + oField.sFieldName + ']').value =='NaN') + document.getElementById(aAux[0] + '][' + aAux[1] + '][' + oField.sFieldName + ']').value = ''; + + document.getElementById(aAux[0]+']['+ aAux[1] + '][' + oField.sFieldName + ']').value = symbol+' '+document.getElementById(aAux[0]+']['+ aAux[1] + '][' + oField.sFieldName + ']').value; + if (this.aFunctions.length > 0) { for (i = 0; i < this.aFunctions.length; i++) { oAux = document.getElementById('form[' + this.sGridName + '][' + aAux[1] + '][' + this.aFunctions[i].sFieldName + ']'); diff --git a/gulliver/system/class.xmlform.php b/gulliver/system/class.xmlform.php index 444d4b04e..03d409ad3 100755 --- a/gulliver/system/class.xmlform.php +++ b/gulliver/system/class.xmlform.php @@ -1613,6 +1613,8 @@ class XmlForm_Field_Currency extends XmlForm_Field_SimpleText { $onkeypress = G::replaceDataField ( $this->onkeypress, $owner->values ); $html = ''; + $currency = preg_replace( '/([#,.])/', '',$this->mask); + if (! $value) $value= $currency; if ($this->renderMode == 'edit'){ //EDIT MODE $readOnlyText = ($this->readOnly == 1 || $this->readOnly == '1') ? 'readOnly="readOnly"' : ''; @@ -1643,6 +1645,50 @@ class XmlForm_Field_Currency extends XmlForm_Field_SimpleText { return $html; } + + /** + * Function renderGrid + * @author alvaro campos sanchez + * @access public + * @param string values + * @param string owner + * @return string + */ + function renderGrid($values = array(), $owner) + { + $result = array (); + $r = 1; + if ($owner->mode != 'view') $this->renderMode = $this->modeForGrid; + + foreach ( $values as $v ) { + $html = ''; + $currency = preg_replace( '/([#,.])/', '',$this->mask); + if (! $v) $v= $currency; + if ($this->renderMode === 'edit'){ //EDIT MODE + $readOnlyText = ($this->readOnly == 1 || $this->readOnly == '1') ? 'readOnly="readOnly"' : ''; + $html .= 'name.']['.$r.']['.$this->name.']" '; + $html .= 'name="form['.$owner->name.']['.$r.']['.$this->name.']" '; + $html .= 'type="text" size="'.$this->size.'" maxlength="'.$this->maxLength.'" '; + $html .= 'value="'.$this->htmlentities($v, ENT_QUOTES, 'utf-8').'" '; + $html .= 'style="'.$this->htmlentities($this->style, ENT_COMPAT, 'utf-8').'" '; + $html .= $this->NSDefaultValue().' '; + $html .= $this->NSRequiredValue().' '; + $html .= $this->NSGridType().' '; + $html .= $this->NSGridLabel().' '; + $html .= '/>'; + }else{ //VIEW MODE + $html .= $this->htmlentities($v, ENT_QUOTES, 'utf-8'); + $html .= 'name.']['.$r.']['.$this->name.']" '; + $html .= 'name="form['.$owner->name.']['.$r.']['.$this->name.']" '; + $html .= 'type="hidden" value="'.$this->htmlentities($v, ENT_QUOTES, 'utf-8').'" />'; + } + $result [] = $html; + $r ++; + } + return $result; + } } /*DEPRECATED*/