BUG 12738 "SQL doesn't work in GRID - Text-Area..." SOLVED
- 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
This commit is contained in:
@@ -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);
|
||||
|
||||
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
|
||||
|
||||
@@ -965,7 +965,8 @@ for(i=0;i<dependentFields.length;i++){if(me.form.getElementIdByName(dependentFie
|
||||
if(me.dependentOf[i]===field)exists=true;if(!exists)me.dependentOf[i]=field;};this.updateDepententFields=function(event){var tempValue;if(me.dependentFields.length===0)return true;var fields=[],Fields=[],i,grid='',row=0;var gridField="";for(i in me.dependentFields){if(me.dependentFields[i].dependentOf){for(var j=0;j<me.dependentFields[i].dependentOf.length;j++){var oAux=me.dependentFields[i].dependentOf[j];if(oAux.name.indexOf('][')>-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;i<newcont.length;i++){var j=me.form.getElementIdByName(newcont[i].name);if(typeof(me.form.aElements[j])!='undefined'){me.form.aElements[j].setValue(newcont[i].value);me.form.aElements[j].setContent(newcont[i].content);me.form.aElements[j].updateDepententFields();}}}
|
||||
else{for(var i=0;i<newcont.length;i++){var oAux=me.form.getElementByName(grid);if(oAux){var oAux2=oAux.getElementByName(row,newcont[i].name);if(oAux2){oAux2.setValue(newcont[i].value);oAux2.setContent(newcont[i].content);oAux2.updateDepententFields();}}}}}else{alert('Invalid response: '+response);}
|
||||
else{for(var i=0;i<newcont.length;i++){var oAux=me.form.getElementByName(grid);if(oAux){var oAux2=oAux.getElementByName(row,newcont[i].name);if(oAux2){oAux2.setValue(newcont[i].value);if(oAux2.element.type!="textarea"){oAux2.setContent(newcont[i].content);}else{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();}}}}}else{alert('Invalid response: '+response);}
|
||||
return true;};this.setValue=function(newValue){me.element.value=newValue;};this.setContent=function(newContent){};this.setAttributes=function(attributes){for(var a in attributes){if(a=='formula'&&attributes[a]){sumaformu(this.element,attributes[a],attributes['mask']);}
|
||||
switch(typeof(attributes[a])){case'string':case'int':case'boolean':if(a!='strTo'){switch(true){case typeof(me[a])==='undefined':case typeof(me[a])==='object':case typeof(me[a])==='function':case a==='isObject':case a==='isArray':break;default:me[a]=attributes[a];}}
|
||||
else{me[a]=attributes[a];}}}};this.value=function(){return me.element.value;};this.toJSONString=function(){return'{"'+me.name+'":'+me.element.value.toJSONString()+'}';};this.highLight=function(){try{G.highLight(me.element);if(G.autoFirstField){me.element.focus();G.autoFirstField=false;setTimeout("G.autoFirstField=true;",1000);}}catch(e){}};}
|
||||
|
||||
@@ -221,7 +221,7 @@ foreach ($dependentFields as $d) {
|
||||
$sendContent[$r]->content->{$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()));
|
||||
|
||||
@@ -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();
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user