From 2ae6da9f1007ad4e69a51653949f6633cadf3f1a Mon Sep 17 00:00:00 2001 From: Luis Fernando Saisa Lopez Date: Thu, 24 Oct 2013 17:00:32 -0400 Subject: [PATCH] BUG 12738 "SQL doesn't work in GRID - Text-Area..." SOLVED MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - SQL doesn't work in GRID - Text-Area fields. - Problema: Al crear una dependencia entre un Dropdown y Textarea en un grid, al añrlo a un Dynaform y ejecutar el caso, la dependiencia no funcionaba, al seleccionar una opcion del Dropdown en el textarea no se mostraba ningun valor, y al adicionar mas filas igual no funcionaba. Solucion: El problema es el siguiente: en la clase "class XmlForm_Field_Textarea" en su metodo "renderGrid" no estaba definido variables de importancia y seteo de las mismas, se completo las variables faltantes. Otro de los problemas que ocasionaba esta dificultad estaba en el archivo JavaScript en el metodo "updateDepententFields" se agrego una validacion cuando es un campo de tipo "textarea", esto porque no se podia utilizar el metodo "G_TextArea" que tambien le faltaba codigo, colocando este codigo faltante tampoco funcionaba. Al crear una dependencia entre un Dropdown y Textarea en un grid la añrlo a un Dynaform, y ejecutar el caso, dependiencia funciona correctamente. Se agrego el siguiente codigo en la clase "class XmlForm_Field_Textarea" en el metodo "renderGrid": ... $this->executeSQL($owner, $r); if (isset($this->sqlOption)) { $firstElement = key($this->sqlOption); } if (isset($firstElement)) { $v = $firstElement; } $arrayOptions[$r] = $v; ... $this->options = $arrayOptions; ... Disponible para la version 2.5.2 --- gulliver/js/form/core/form.js | 15 ++++++++++++++- gulliver/js/maborak/core/maborak.js | 3 ++- gulliver/methods/defaultAjax.php | 2 +- gulliver/system/class.xmlform.php | 26 ++++++++++++++++++-------- 4 files changed, 35 insertions(+), 11 deletions(-) diff --git a/gulliver/js/form/core/form.js b/gulliver/js/form/core/form.js index 75d6b58b3..522eb477e 100755 --- a/gulliver/js/form/core/form.js +++ b/gulliver/js/form/core/form.js @@ -192,7 +192,20 @@ function G_Field ( form, element, name ) var oAux2 = oAux.getElementByName(row, newcont[i].name); if (oAux2) { oAux2.setValue(newcont[i].value); - oAux2.setContent(newcont[i].content); + + if (oAux2.element.type != "textarea") { + oAux2.setContent(newcont[i].content); + } else { + //This code fragment is copy of method G_Text.setContent() + oAux2.element.value = ""; + + if (newcont[i].content.options) { + if (newcont[i].content.options[0]) { + oAux2.element.value = newcont[i].content.options[0].value; + } + } + } + oAux2.updateDepententFields(); // this line is also needed to trigger the onchange event to trigger the calculation of // sumatory or average functions in text fields diff --git a/gulliver/js/maborak/core/maborak.js b/gulliver/js/maborak/core/maborak.js index 7ef5ba2e0..3e38fa51c 100644 --- a/gulliver/js/maborak/core/maborak.js +++ b/gulliver/js/maborak/core/maborak.js @@ -965,7 +965,8 @@ for(i=0;i-1){var arrayAux=oAux.name.split("][");grid=arrayAux[0];row=parseInt(arrayAux[1]);fieldName=arrayAux[2];gridField=gridGetAllFieldAndValue(oAux.name,0);if(Fields.length>0){aux=Fields;aux.push('?');if(aux.join('*').indexOf(fieldName+'*')==-1){Fields.push(fieldName);eval("var oAux2 = {"+fieldName+":'"+oAux.value()+"'}");fields=fields.concat(oAux2);}}else{Fields.push(fieldName);eval("var oAux2 = {"+fieldName+":'"+oAux.value()+"'}");fields=fields.concat(oAux2);}} else{aux=Fields;aux.push('?');oAux=me.dependentFields[i].dependentOf[0];if(Fields.length>0){if(aux.join('*').indexOf(oAux.name+'*')==-1){Fields.push(oAux.name);fields=fields.concat(me.dependentFields[i].dependentOf);}}else{Fields.push(oAux.name);fields=fields.concat(me.dependentFields[i].dependentOf);}}}}} var callServer;callServer=new leimnud.module.rpc.xmlhttp({url:me.form.ajaxServer,async:false,method:"POST",args:"function=reloadField"+"&form="+encodeURIComponent(me.form.id)+"&fields="+encodeURIComponent(fields.toJSONString())+((grid!="")?"&grid="+grid+((gridField!="")?"&gridField="+encodeURIComponent("{"+gridField+"}"):""):"")+((row>0)?"&row="+row:"")});callServer.make();var response=callServer.xmlhttp.responseText;if(response.substr(0,1)==='['){var newcont;eval('newcont='+response+';');if(grid==''){for(var i=0;icontent->{$attribute} = $value; break; case 'options': - if ($sendContent[$r]->content->type != 'text') { + if ($sendContent[$r]->content->type != "text" && $sendContent[$r]->content->type != "textarea") { $sendContent[$r]->content->{$attribute} = toJSArray($value); } else { $sendContent[$r]->content->{$attribute} = toJSArray((isset($value[$_POST["row"]])? array($value[$_POST["row"]]) : array())); diff --git a/gulliver/system/class.xmlform.php b/gulliver/system/class.xmlform.php index d00e52253..cdaf17738 100755 --- a/gulliver/system/class.xmlform.php +++ b/gulliver/system/class.xmlform.php @@ -1982,24 +1982,32 @@ class XmlForm_Field_Textarea extends XmlForm_Field * @param string owner * @return string */ - public function renderGrid ($values = null, $owner = null) + public function renderGrid ($values = array(), $owner = null) { $this->gridFieldType = 'textarea'; if ($owner->mode != 'view') { $this->renderMode = $this->modeForGrid; } - $result = array (); + + $result = array(); + $arrayOptions = array(); + $r = 1; foreach ($values as $v) { - $this->executeSQL( $owner, $r ); - if (isset( $this->sqlOption )) { - $firstElement = key( $this->sqlOption ); - if (isset( $firstElement )) { - $v = $firstElement; - } + $this->executeSQL($owner, $r); + + if (isset($this->sqlOption)) { + $firstElement = key($this->sqlOption); } + + if (isset($firstElement)) { + $v = $firstElement; + } + + $arrayOptions[$r] = $v; + $scrollStyle = $this->style . "overflow:scroll;overflow-y:scroll;overflow-x:hidden;overflow:-moz-scrollbars-vertical;"; $html = ''; if ($this->renderMode == 'edit') { @@ -2031,6 +2039,8 @@ class XmlForm_Field_Textarea extends XmlForm_Field $result[] = $html; $r ++; } + + $this->options = $arrayOptions; return $result; } }