BUG 5648 solved. Dependent Fields work now in onload dynaform
This commit is contained in:
@@ -99,9 +99,10 @@ function G_Field ( form, element, name )
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.updateDepententFields=function(event) {
|
this.updateDepententFields=function(event) {
|
||||||
|
|
||||||
var tempValue;
|
var tempValue;
|
||||||
if (me.dependentFields.length===0) return true;
|
if (me.dependentFields.length===0) return true;
|
||||||
var fields=[],i,grid='',row=0;
|
var fields=[],Fields = [],i,grid='',row=0;
|
||||||
for(i in me.dependentFields) {
|
for(i in me.dependentFields) {
|
||||||
if (me.dependentFields[i].dependentOf) {
|
if (me.dependentFields[i].dependentOf) {
|
||||||
for (var j = 0; j < me.dependentFields[i].dependentOf.length; j++) {
|
for (var j = 0; j < me.dependentFields[i].dependentOf.length; j++) {
|
||||||
@@ -110,11 +111,34 @@ function G_Field ( form, element, name )
|
|||||||
var aAux = oAux.name.split('][');
|
var aAux = oAux.name.split('][');
|
||||||
grid = aAux[0];
|
grid = aAux[0];
|
||||||
row = aAux[1];
|
row = aAux[1];
|
||||||
eval("var oAux2 = {" + aAux[2] + ":'" + oAux.value() + "'}");
|
fieldName = aAux[2];
|
||||||
fields = fields.concat(oAux2);
|
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 {
|
else {
|
||||||
fields = fields.concat(me.dependentFields[i].dependentOf);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,43 +157,40 @@ function G_Field ( form, element, name )
|
|||||||
var newcont;
|
var newcont;
|
||||||
eval('newcont=' + response + ';');
|
eval('newcont=' + response + ';');
|
||||||
if (grid == '') {
|
if (grid == '') {
|
||||||
//alert('1');
|
|
||||||
for(var i=0;i<newcont.length;i++) {
|
for(var i=0;i<newcont.length;i++) {
|
||||||
|
//alert(newcont[i].name + '-' + newcont[i].value);
|
||||||
var j=me.form.getElementIdByName(newcont[i].name);
|
var j=me.form.getElementIdByName(newcont[i].name);
|
||||||
me.form.aElements[j].setValue(newcont[i].value);
|
me.form.aElements[j].setValue(newcont[i].value);
|
||||||
me.form.aElements[j].setContent(newcont[i].content);
|
me.form.aElements[j].setContent(newcont[i].content);
|
||||||
if (me.form.aElements[j].element.fireEvent) {
|
me.form.aElements[j].updateDepententFields();
|
||||||
|
/*if (me.form.aElements[j].element.fireEvent) {
|
||||||
me.form.aElements[j].element.fireEvent("onchange");
|
me.form.aElements[j].element.fireEvent("onchange");
|
||||||
//alert ("fireEvent");
|
|
||||||
} else {
|
} else {
|
||||||
//alert ("initEvent");
|
|
||||||
var evObj = document.createEvent('HTMLEvents');
|
var evObj = document.createEvent('HTMLEvents');
|
||||||
evObj.initEvent( 'change', true, true );
|
evObj.initEvent( 'change', true, true );
|
||||||
me.form.aElements[j].element.dispatchEvent(evObj);
|
me.form.aElements[j].element.dispatchEvent(evObj);
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//alert('2: ' + newcont.length);
|
|
||||||
for(var i=0;i<newcont.length;i++) {
|
for(var i=0;i<newcont.length;i++) {
|
||||||
var oAux = me.form.getElementByName(grid);
|
var oAux = me.form.getElementByName(grid);
|
||||||
if (oAux) {
|
if (oAux) {
|
||||||
var oAux2 = oAux.getElementByName(row, newcont[i].name);
|
var oAux2 = oAux.getElementByName(row, newcont[i].name);
|
||||||
if (oAux2) {
|
if (oAux2) {
|
||||||
|
oAux2.setValue(newcont[i].value);
|
||||||
oAux2.setContent(newcont[i].content);
|
oAux2.setContent(newcont[i].content);
|
||||||
if (newcont[i].content.type == 'dropdown') {
|
oAux2.updateDepententFields();
|
||||||
oAux2.setValue(newcont[i].value);
|
|
||||||
}
|
|
||||||
// this line is also needed to trigger the onchange event to trigger the calculation of
|
// this line is also needed to trigger the onchange event to trigger the calculation of
|
||||||
// sumatory or average functions in text fields
|
// sumatory or average functions in text fields
|
||||||
//if (i == (newcont.length-1)){
|
//if (i == (newcont.length-1)){
|
||||||
if (oAux2.element.fireEvent) {
|
/* if (oAux2.element.fireEvent) {
|
||||||
oAux2.element.fireEvent("onchange");
|
oAux2.element.fireEvent("onchange");
|
||||||
} else {
|
} else {
|
||||||
var evObj = document.createEvent('HTMLEvents');
|
var evObj = document.createEvent('HTMLEvents');
|
||||||
evObj.initEvent( 'change', true, true );
|
evObj.initEvent( 'change', true, true );
|
||||||
oAux2.element.dispatchEvent(evObj);
|
oAux2.element.dispatchEvent(evObj);
|
||||||
}
|
}*/
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -181,6 +202,8 @@ function G_Field ( form, element, name )
|
|||||||
// this checks the dependent fields that doesn't have assigned a value
|
// this checks the dependent fields that doesn't have assigned a value
|
||||||
// but their master yes and their dependence must be fulfilled within one
|
// but their master yes and their dependence must be fulfilled within one
|
||||||
// onchange event
|
// onchange event
|
||||||
|
|
||||||
|
/*
|
||||||
if (grid!='')
|
if (grid!='')
|
||||||
{
|
{
|
||||||
var checkCallServer;
|
var checkCallServer;
|
||||||
@@ -200,9 +223,9 @@ function G_Field ( form, element, name )
|
|||||||
var oAuxJs;
|
var oAuxJs;
|
||||||
for ( index in dependentList ){
|
for ( index in dependentList ){
|
||||||
field = 'form[grid]['+ row +']['+dependentList[index]+']';
|
field = 'form[grid]['+ row +']['+dependentList[index]+']';
|
||||||
// alert(field);
|
|
||||||
oAuxJs = document.getElementById(field);
|
oAuxJs = document.getElementById(field);
|
||||||
// alert (oAuxJs.value);
|
|
||||||
if ( oAuxJs!=null ){
|
if ( oAuxJs!=null ){
|
||||||
if (oAuxJs.value!="") {
|
if (oAuxJs.value!="") {
|
||||||
if ( oAuxJs.fireEvent ) {
|
if ( oAuxJs.fireEvent ) {
|
||||||
@@ -215,7 +238,7 @@ function G_Field ( form, element, name )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
this.setValue = function(newValue) {
|
this.setValue = function(newValue) {
|
||||||
@@ -427,13 +450,13 @@ function G_Text( form, element, name, type )
|
|||||||
break;
|
break;
|
||||||
case "Alpha":
|
case "Alpha":
|
||||||
if (keyCode==8) return true;
|
if (keyCode==8) return true;
|
||||||
patron =/[A-Za-z\sáéÃóúäëïöüñçÇÑÃ<EFBFBD>ÉÃ<EFBFBD>ÓÚÄËÃ<EFBFBD>ÖÜ]/;
|
patron =/[A-Za-z\s<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>]/;
|
||||||
te = String.fromCharCode(keyCode);
|
te = String.fromCharCode(keyCode);
|
||||||
return patron.test(te);
|
return patron.test(te);
|
||||||
break;
|
break;
|
||||||
case "AlphaNum":
|
case "AlphaNum":
|
||||||
if (keyCode==8) return true;
|
if (keyCode==8) return true;
|
||||||
patron =/[A-Za-z0-9\sáéÃóúäëïöüñçÇÑÃ<EFBFBD>ÉÃ<EFBFBD>ÓÚÄËÃ<EFBFBD>ÖÜ]/;
|
patron =/[A-Za-z0-9\s<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>]/;
|
||||||
te = String.fromCharCode(keyCode);
|
te = String.fromCharCode(keyCode);
|
||||||
return patron.test(te);
|
return patron.test(te);
|
||||||
break;
|
break;
|
||||||
@@ -744,7 +767,7 @@ function G_Text( form, element, name, type )
|
|||||||
|
|
||||||
if(this.validate=="Email")
|
if(this.validate=="Email")
|
||||||
{
|
{
|
||||||
var pat=/^[\w\_\-\.çñ]{2,255}@[\w\_\-]{2,255}\.[a-z]{1,3}\.?[a-z]{0,3}$/;
|
var pat=/^[\w\_\-\.<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>]{2,255}@[\w\_\-]{2,255}\.[a-z]{1,3}\.?[a-z]{0,3}$/;
|
||||||
if(!pat.test(this.element.value))
|
if(!pat.test(this.element.value))
|
||||||
{
|
{
|
||||||
this.element.className=this.element.className.split(" ")[0]+" FormFieldInvalid";
|
this.element.className=this.element.className.split(" ")[0]+" FormFieldInvalid";
|
||||||
|
|||||||
@@ -324,16 +324,31 @@ var G_Grid = function(oForm, sGridName){
|
|||||||
aObjects = null;
|
aObjects = null;
|
||||||
break;
|
break;
|
||||||
case 'select': //DROPDOWN
|
case 'select': //DROPDOWN
|
||||||
|
var oNewSelect;
|
||||||
aObjects = oNewRow.getElementsByTagName('td')[i].getElementsByTagName('select');
|
aObjects = oNewRow.getElementsByTagName('td')[i].getElementsByTagName('select');
|
||||||
if (aObjects){
|
if (aObjects){
|
||||||
newID = aObjects[0].id.replace(/\[1\]/g, '\[' + currentRow + '\]');
|
newID = aObjects[0].id.replace(/\[1\]/g, '\[' + currentRow + '\]');
|
||||||
aObjects[0].id = newID;
|
aObjects[0].id = newID;
|
||||||
aObjects[0].name = newID;
|
aObjects[0].name = newID;
|
||||||
|
|
||||||
|
oNewSelect = document.createElement(aObjects[0].tagName);
|
||||||
|
oNewSelect.id = newID;
|
||||||
|
oNewSelect.name = newID;
|
||||||
|
oNewSelect.setAttribute('class','module_app_input___gray');
|
||||||
|
|
||||||
|
aAttributes = aObjects[0].attributes;
|
||||||
|
for (a=0; a < aAttributes.length; a++){
|
||||||
|
if (aAttributes[a].name.indexOf('pm:') != -1){
|
||||||
|
oNewSelect.setAttribute(aAttributes[a].name,aAttributes[a].value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
attributes = elementAttributesNS(aObjects[0], 'pm');
|
attributes = elementAttributesNS(aObjects[0], 'pm');
|
||||||
|
var MyAtt = attributes;
|
||||||
if (attributes.defaultvalue != '' && typeof attributes.defaultvalue != 'undefined'){
|
if (attributes.defaultvalue != '' && typeof attributes.defaultvalue != 'undefined'){
|
||||||
defaultValue = attributes.defaultvalue;
|
defaultValue = attributes.defaultvalue;
|
||||||
//Set '' for Default Value when dropdown has dependent fields.
|
//Set '' for Default Value when dropdown has dependent fields.
|
||||||
if (attributes.dependent == '1') defaultValue = '';
|
//if (attributes.dependent == '1') defaultValue = '';
|
||||||
}else{
|
}else{
|
||||||
defaultValue = '';
|
defaultValue = '';
|
||||||
}
|
}
|
||||||
@@ -361,12 +376,14 @@ var G_Grid = function(oForm, sGridName){
|
|||||||
oAux.options.add(oOption);
|
oAux.options.add(oOption);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
aObjects[0].innerHTML = ''; //Delete options
|
oNewSelect.innerHTML = ''; //Delete options
|
||||||
|
//aObjects[0].innerHTML = ''; //Delete options
|
||||||
for (var r =0; r < oAux.options.length; r++){
|
for (var r =0; r < oAux.options.length; r++){
|
||||||
var xOption = document.createElement('OPTION');
|
var xOption = document.createElement('OPTION');
|
||||||
xOption.value = oAux.options[r].value;
|
xOption.value = oAux.options[r].value;
|
||||||
xOption.text = oAux.options[r].text;
|
xOption.text = oAux.options[r].text;
|
||||||
aObjects[0].options.add(xOption);
|
//aObjects[0].options.add(xOption);
|
||||||
|
oNewSelect.options.add(xOption);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
//Set Default Value if it's not a Dependent Field
|
//Set Default Value if it's not a Dependent Field
|
||||||
@@ -381,7 +398,8 @@ var G_Grid = function(oForm, sGridName){
|
|||||||
}
|
}
|
||||||
oAux.options.add(oOption);
|
oAux.options.add(oOption);
|
||||||
}
|
}
|
||||||
aObjects[0].innerHTML = ''; //Delete options
|
//aObjects[0].innerHTML = ''; //Delete options
|
||||||
|
oNewSelect.innerHTML = ''; //Delete options
|
||||||
for (var r =0; r < oAux.options.length; r++){
|
for (var r =0; r < oAux.options.length; r++){
|
||||||
var xOption = document.createElement('OPTION');
|
var xOption = document.createElement('OPTION');
|
||||||
xOption.value = oAux.options[r].value;
|
xOption.value = oAux.options[r].value;
|
||||||
@@ -395,11 +413,15 @@ var G_Grid = function(oForm, sGridName){
|
|||||||
xOption.setAttribute('selected','selected');
|
xOption.setAttribute('selected','selected');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
aObjects[0].options.add(xOption);
|
//aObjects[0].options.add(xOption);
|
||||||
|
oNewSelect.options.add(xOption);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//TODO: Implement Default Value and Dependent Fields Trigger for grid dropdowns
|
//TODO: Implement Default Value and Dependent Fields Trigger for grid dropdowns
|
||||||
}
|
}
|
||||||
|
parentSelect = aObjects[0].parentNode;
|
||||||
|
parentSelect.removeChild(aObjects[0]);
|
||||||
|
parentSelect.appendChild(oNewSelect);
|
||||||
}
|
}
|
||||||
aObjects = oNewRow.getElementsByTagName('td')[i].getElementsByTagName('input');
|
aObjects = oNewRow.getElementsByTagName('td')[i].getElementsByTagName('input');
|
||||||
if (aObjects.length > 0){
|
if (aObjects.length > 0){
|
||||||
@@ -448,6 +470,23 @@ var G_Grid = function(oForm, sGridName){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//Fire Update Dependent Fields for any item with dependentfields and not included in dependencie
|
||||||
|
var xIsDependentOf = [];
|
||||||
|
var exist = false;
|
||||||
|
for (i=0; i < this.aFields.length; i++){
|
||||||
|
oAux = this.getElementByName(currentRow, this.aFields[i].sFieldName);
|
||||||
|
if (oAux.dependentFields.length > 0){
|
||||||
|
exist = false;
|
||||||
|
for (m=0; m < xIsDependentOf.length; m++)
|
||||||
|
if (xIsDependentOf[m] == oAux.name) exist = true;
|
||||||
|
for (j=0; j < oAux.dependentFields.length; j++){
|
||||||
|
xIsDependentOf.push(oAux.dependentFields[j].name);
|
||||||
|
}
|
||||||
|
if (!exist){
|
||||||
|
oAux.updateDepententFields();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
//Fires OnAddRow Event
|
//Fires OnAddRow Event
|
||||||
if (this.onaddrow) {
|
if (this.onaddrow) {
|
||||||
this.onaddrow(currentRow);
|
this.onaddrow(currentRow);
|
||||||
|
|||||||
@@ -56,6 +56,7 @@
|
|||||||
$G_FORM->id=urlDecode($_POST['form']);
|
$G_FORM->id=urlDecode($_POST['form']);
|
||||||
//$G_FORM->values=isset($_SESSION[$G_FORM->id]) ? $_SESSION[$G_FORM->id] : array();
|
//$G_FORM->values=isset($_SESSION[$G_FORM->id]) ? $_SESSION[$G_FORM->id] : array();
|
||||||
$newValues=($json->decode(urlDecode(stripslashes($_POST['fields']))));
|
$newValues=($json->decode(urlDecode(stripslashes($_POST['fields']))));
|
||||||
|
$newValues = array_unique($newValues);
|
||||||
if (isset($_POST['grid'])) {
|
if (isset($_POST['grid'])) {
|
||||||
$_POST['row'] = (int)$_POST['row'];
|
$_POST['row'] = (int)$_POST['row'];
|
||||||
$aAux = array();
|
$aAux = array();
|
||||||
@@ -71,7 +72,6 @@
|
|||||||
unset($newValues[$sKey]->$aKeys[0]);
|
unset($newValues[$sKey]->$aKeys[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Resolve dependencies
|
//Resolve dependencies
|
||||||
//Returns an array ($dependentFields) with the names of the fields
|
//Returns an array ($dependentFields) with the names of the fields
|
||||||
//that depends of fields passed through AJAX ($_GET/$_POST)
|
//that depends of fields passed through AJAX ($_GET/$_POST)
|
||||||
@@ -82,7 +82,6 @@
|
|||||||
//Search dependent fields
|
//Search dependent fields
|
||||||
foreach($newValues[$r] as $k => $v) {
|
foreach($newValues[$r] as $k => $v) {
|
||||||
if (!is_array($v)) {
|
if (!is_array($v)) {
|
||||||
//echo 'NoASrray';
|
|
||||||
$myDependentFields = subDependencies( $k , $G_FORM , $aux );
|
$myDependentFields = subDependencies( $k , $G_FORM , $aux );
|
||||||
$_SESSION[$G_FORM->id][$k] = $v;
|
$_SESSION[$G_FORM->id][$k] = $v;
|
||||||
}
|
}
|
||||||
@@ -96,8 +95,6 @@
|
|||||||
//$_SESSION[$G_FORM->id][$k] = $v;
|
//$_SESSION[$G_FORM->id][$k] = $v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//g::pr($myDependentFields);
|
|
||||||
|
|
||||||
$G_FORM->values=isset($_SESSION[$G_FORM->id]) ? $_SESSION[$G_FORM->id] : array();
|
$G_FORM->values=isset($_SESSION[$G_FORM->id]) ? $_SESSION[$G_FORM->id] : array();
|
||||||
|
|
||||||
$dependentFields=array_unique($dependentFields);
|
$dependentFields=array_unique($dependentFields);
|
||||||
@@ -105,7 +102,6 @@
|
|||||||
//Parse and update the new content
|
//Parse and update the new content
|
||||||
$template = PATH_CORE . 'templates/xmlform.html';
|
$template = PATH_CORE . 'templates/xmlform.html';
|
||||||
$newContent=$G_FORM->getFields($template, (isset($_POST['row']) ? $_POST['row'] : -1));
|
$newContent=$G_FORM->getFields($template, (isset($_POST['row']) ? $_POST['row'] : -1));
|
||||||
|
|
||||||
//Returns the dependentFields's content
|
//Returns the dependentFields's content
|
||||||
$sendContent=array();
|
$sendContent=array();
|
||||||
$r=0;
|
$r=0;
|
||||||
@@ -176,10 +172,10 @@
|
|||||||
for( $r=0 ; $r < sizeof($myDependentFields) ; $r++ ) {
|
for( $r=0 ; $r < sizeof($myDependentFields) ; $r++ ) {
|
||||||
if ($myDependentFields[$r]=="") unset($myDependentFields[$r]);
|
if ($myDependentFields[$r]=="") unset($myDependentFields[$r]);
|
||||||
}
|
}
|
||||||
$mD = $myDependentFields;
|
// $mD = $myDependentFields;
|
||||||
foreach( $mD as $ki) {
|
// foreach( $mD as $ki) {
|
||||||
$myDependentFields = array_merge( $myDependentFields , subDependencies( $ki , $G_FORM , $aux ) );
|
// $myDependentFields = array_merge( $myDependentFields , subDependencies( $ki , $G_FORM , $aux ) );
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!array_key_exists( $k , $G_FORM->fields[$grid]->fields )) return array();
|
if (!array_key_exists( $k , $G_FORM->fields[$grid]->fields )) return array();
|
||||||
@@ -194,7 +190,7 @@
|
|||||||
for( $r=0 ; $r < sizeof($myDependentFields) ; $r++ ) {
|
for( $r=0 ; $r < sizeof($myDependentFields) ; $r++ ) {
|
||||||
if ($myDependentFields[$r]=="") unset($myDependentFields[$r]);
|
if ($myDependentFields[$r]=="") unset($myDependentFields[$r]);
|
||||||
}
|
}
|
||||||
$mD = $myDependentFields;
|
// $mD = $myDependentFields;
|
||||||
// foreach( $mD as $ki) {
|
// foreach( $mD as $ki) {
|
||||||
// $myDependentFields = array_merge( $myDependentFields , subDependencies( $ki , $G_FORM , $aux, $grid) );
|
// $myDependentFields = array_merge( $myDependentFields , subDependencies( $ki , $G_FORM , $aux, $grid) );
|
||||||
// }
|
// }
|
||||||
|
|||||||
@@ -198,6 +198,7 @@ class XmlForm_Field {
|
|||||||
*/
|
*/
|
||||||
private function executePropel(&$owner, $row = -1)
|
private function executePropel(&$owner, $row = -1)
|
||||||
{
|
{
|
||||||
|
//g::pr($row);
|
||||||
if (! isset ( $owner->values [$this->name] )) {
|
if (! isset ( $owner->values [$this->name] )) {
|
||||||
if ($row > - 1) {
|
if ($row > - 1) {
|
||||||
$owner->values [$this->name] = array ();
|
$owner->values [$this->name] = array ();
|
||||||
@@ -206,18 +207,35 @@ class XmlForm_Field {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (! is_array ( $owner->values [$this->name] )) {
|
if (! is_array ( $owner->values [$this->name] )) {
|
||||||
|
//echo '1';
|
||||||
$query = G::replaceDataField ( $this->sql, $owner->values );
|
$query = G::replaceDataField ( $this->sql, $owner->values );
|
||||||
} else {
|
} else {
|
||||||
$aAux = array ();
|
$aAux = array ();
|
||||||
foreach ( $owner->values as $key => $data ) {
|
foreach ( $owner->values as $key => $data ) {
|
||||||
if (is_array ( $data )) {
|
if (is_array ( $data )) {
|
||||||
$aAux [$key] = isset ( $data [$row] ) ? $data [$row] : '';
|
//echo '3:'.$key.' ';
|
||||||
|
if (isset ( $data [$row] )){
|
||||||
|
$qValue = $data [$row];
|
||||||
|
}else{
|
||||||
|
if (isset($owner->fields[$key]->selectedValue)){
|
||||||
|
$qValue = $owner->fields[$key]->selectedValue;
|
||||||
|
}else{
|
||||||
|
$qValue = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$aAux [$key] = $qValue;
|
||||||
|
//$aAux [$key] = isset ( $data [$row] ) ? $data [$row] : '';
|
||||||
} else {
|
} else {
|
||||||
|
//echo '4'.$key.' ';
|
||||||
$aAux [$key] = $data;
|
$aAux [$key] = $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//echo '2';
|
||||||
|
//g::pr($aAux);
|
||||||
$query = G::replaceDataField ( $this->sql, $aAux );
|
$query = G::replaceDataField ( $this->sql, $aAux );
|
||||||
}
|
}
|
||||||
|
//echo $query;
|
||||||
|
|
||||||
$result = array ();
|
$result = array ();
|
||||||
if ($this->sqlConnection == 'dbarray') {
|
if ($this->sqlConnection == 'dbarray') {
|
||||||
@@ -2516,6 +2534,7 @@ class XmlForm_Field_Dropdown extends XmlForm_Field {
|
|||||||
var $saveLabel = 0;
|
var $saveLabel = 0;
|
||||||
var $modeGridDrop = '';
|
var $modeGridDrop = '';
|
||||||
var $renderMode = '';
|
var $renderMode = '';
|
||||||
|
var $selectedValue = '';
|
||||||
function validateValue($value, &$owner)
|
function validateValue($value, &$owner)
|
||||||
{
|
{
|
||||||
/*$this->executeSQL( $owner );
|
/*$this->executeSQL( $owner );
|
||||||
@@ -2533,12 +2552,15 @@ class XmlForm_Field_Dropdown extends XmlForm_Field {
|
|||||||
*/
|
*/
|
||||||
function render($value = NULL, $owner = NULL, $rowId = '', $onlyValue = false, $row = -1, $therow = -1)
|
function render($value = NULL, $owner = NULL, $rowId = '', $onlyValue = false, $row = -1, $therow = -1)
|
||||||
{
|
{
|
||||||
|
//g::pr($owner->fields);
|
||||||
|
//echo $row.' - '.$therow;
|
||||||
//Returns value from a PMTable when it is exists.
|
//Returns value from a PMTable when it is exists.
|
||||||
if (($this->pmconnection != '') && ($this->pmfield != '') && $value == NULL) {
|
if (($this->pmconnection != '') && ($this->pmfield != '') && $value == NULL) {
|
||||||
$value = $this->getPMTableValue($owner);
|
$value = $this->getPMTableValue($owner);
|
||||||
}
|
}
|
||||||
//Recalculate SQL options if $therow is not defined or the row id equal
|
//Recalculate SQL options if $therow is not defined or the row id equal
|
||||||
if ($therow == - 1) {
|
if ($therow == -1) {
|
||||||
|
//echo 'Entro:'.$this->dependentFields;
|
||||||
$this->executeSQL ( $owner, $row );
|
$this->executeSQL ( $owner, $row );
|
||||||
} else {
|
} else {
|
||||||
if ($row == $therow) {
|
if ($row == $therow) {
|
||||||
@@ -2584,6 +2606,7 @@ class XmlForm_Field_Dropdown extends XmlForm_Field {
|
|||||||
$html .= 'name="form' . $rowId . '[' . $this->name . ']" ';
|
$html .= 'name="form' . $rowId . '[' . $this->name . ']" ';
|
||||||
$html .= 'value="'.(($findValue != '') ? $findValue : $firstValue).'" />';
|
$html .= 'value="'.(($findValue != '') ? $findValue : $firstValue).'" />';
|
||||||
}
|
}
|
||||||
|
$this->selectedValue = ($findValue != '') ? $findValue : $firstValue;
|
||||||
}else{ //VIEW MODE
|
}else{ //VIEW MODE
|
||||||
$findValue = '';
|
$findValue = '';
|
||||||
$firstValue = '';
|
$firstValue = '';
|
||||||
@@ -3025,11 +3048,11 @@ class XmlForm_Field_Grid extends XmlForm_Field
|
|||||||
foreach ( $arrayKeys as $key ){
|
foreach ( $arrayKeys as $key ){
|
||||||
if (isset($this->fields[$key]->defaultValue)){
|
if (isset($this->fields[$key]->defaultValue)){
|
||||||
$emptyValue = $this->fields[$key]->defaultValue;
|
$emptyValue = $this->fields[$key]->defaultValue;
|
||||||
if (isset($this->fields[$key]->dependentFields)){
|
/** if (isset($this->fields[$key]->dependentFields)){
|
||||||
if ($this->fields[$key]->dependentFields != ''){
|
if ($this->fields[$key]->dependentFields != ''){
|
||||||
$emptyValue = '';
|
$emptyValue = '';
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}else{
|
}else{
|
||||||
$emptyValue = '';
|
$emptyValue = '';
|
||||||
}
|
}
|
||||||
@@ -3064,10 +3087,25 @@ class XmlForm_Field_Grid extends XmlForm_Field
|
|||||||
if (! isset ( $values ) || ! is_array ( $values ) || sizeof ( $values ) == 0) {
|
if (! isset ( $values ) || ! is_array ( $values ) || sizeof ( $values ) == 0) {
|
||||||
$values = array_keys ( $this->fields );
|
$values = array_keys ( $this->fields );
|
||||||
}
|
}
|
||||||
|
if ($therow != -1){
|
||||||
|
//Check if values arrary is complete to can flip.
|
||||||
|
$xValues = array();
|
||||||
|
$aRow = $values[$therow];
|
||||||
|
for ($c=1; $c <= $therow; $c++){
|
||||||
|
if ($c == $therow){
|
||||||
|
$xValues[$therow] = $aRow;
|
||||||
|
}else{
|
||||||
|
foreach ($aRow as $key=>$value){
|
||||||
|
$xValues[$c][$key] = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$values = $xValues;
|
||||||
|
}
|
||||||
$aValuekeys = array_keys ( $values );
|
$aValuekeys = array_keys ( $values );
|
||||||
if (count ( $aValuekeys ) > 0 && ( int ) $aValuekeys [0] == 1)
|
if (count ( $aValuekeys ) > 0 && ( int ) $aValuekeys [0] == 1)
|
||||||
$values = $this->flipValues ( $values );
|
$values = $this->flipValues ( $values );
|
||||||
|
//if ($therow == 1)g::pr($values);
|
||||||
$this->rows = count ( reset ( $values ) );
|
$this->rows = count ( reset ( $values ) );
|
||||||
if (isset ( $owner->values )) {
|
if (isset ( $owner->values )) {
|
||||||
foreach ( $owner->values as $key => $value ) {
|
foreach ( $owner->values as $key => $value ) {
|
||||||
@@ -4408,7 +4446,8 @@ class xmlformTemplate extends Smarty
|
|||||||
if (! is_array ( $value )) {
|
if (! is_array ( $value )) {
|
||||||
if ($form->type == 'grid') {
|
if ($form->type == 'grid') {
|
||||||
$aAux = array ();
|
$aAux = array ();
|
||||||
for($i = 0; $i < count ( $form->owner->values [$form->name] ); $i ++) {
|
$index = ($therow >count ( $form->owner->values [$form->name] ))? $therow : count($form->owner->values [$form->name] );
|
||||||
|
for($i = 0; $i < $index; $i ++) {
|
||||||
$aAux [] = '';
|
$aAux [] = '';
|
||||||
}
|
}
|
||||||
$result ['form'] [$k] = $form->fields [$k]->renderGrid ( $aAux, $form );
|
$result ['form'] [$k] = $form->fields [$k]->renderGrid ( $aAux, $form );
|
||||||
@@ -4416,10 +4455,9 @@ class xmlformTemplate extends Smarty
|
|||||||
$result ['form'] [$k] = $form->fields [$k]->render ( $value, $form );
|
$result ['form'] [$k] = $form->fields [$k]->render ( $value, $form );
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isset ( $form->owner )) {
|
/*if (isset ( $form->owner )) {
|
||||||
|
|
||||||
if (count ( $value ) < count ( $form->owner->values [$form->name] )) {
|
if (count ( $value ) < count ( $form->owner->values [$form->name] )) {
|
||||||
|
|
||||||
$i = count ( $value );
|
$i = count ( $value );
|
||||||
$j = count ( $form->owner->values [$form->name] );
|
$j = count ( $form->owner->values [$form->name] );
|
||||||
|
|
||||||
@@ -4427,11 +4465,9 @@ class xmlformTemplate extends Smarty
|
|||||||
$value [] = '';
|
$value [] = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
if ($v->type == 'grid') {
|
if ($v->type == 'grid') {
|
||||||
|
|
||||||
$result ['form'] [$k] = $form->fields [$k]->renderGrid ( $value, $form, $therow );
|
$result ['form'] [$k] = $form->fields [$k]->renderGrid ( $value, $form, $therow );
|
||||||
} else {
|
} else {
|
||||||
if ($v->type == 'dropdown') {
|
if ($v->type == 'dropdown') {
|
||||||
|
|||||||
Reference in New Issue
Block a user