Dynamical select value of combo populated from combo_connector.php


#1

Hi,
I have a form populated from a XML loading the combo data from a database via combo_connector

I can’t figure out how to set the selected value


#2

add onXLE event to combo and then select option:

myCombo.attachEvent('onXLE', function() {
      myCombo.selectOption(optionIndex);
}

#3

Hi klysial,

thanks for the answer. I’m not sure to understand. the object “myCombo” isn’t create in javascript but in xml so I dont see how to attach the event without the combo name

item type=“combo” label=“Corps de métier” connector="…/views/metier/combo.php" name=“corps_de_metier” offsetLeft=“15”/


#4

Do the following.
myCombo = formObject.getCombo(‘corps_de_metier’);
and then you can use the above


#5

Hi klysial,

I tried the following without success:
metierForm = myLayout3.cells(“b”).attachForm();
metierForm.loadStruct("/views/employe/form_metier.xml");
metierForm.load(’/views/employe/form_metier.php?id=’+uid);
console.log(metierForm);
myCombo = metierForm.getCombo(“corps_de_metier”);
console.log(myCombo);
myCombo.attachEvent(‘onXLE’, function() {
myCombo.selectOption(optionIndex);
});

but myCombo seems to be null:
home.php:296 Uncaught TypeError: Cannot read property ‘attachEvent’ of null
at createWindow (home.php:296)
at window.. (home.php:175)
at window..a.callEvent (dhtmlx.js:9)
at dhtmlx.js:9

form_metier.xml contain:







#6

note that you should address to the combo object after the actual loading of the from structure.
So you should use the callback function.
smth:

metierForm.loadStruct("/views/employe/form_metier.xml",function(){
   metierForm.load(’/views/employe/form_metier.php?id=’+uid,function(){
      console.log(metierForm);
      myCombo = metierForm.getCombo(“corps_de_metier”);
      console.log(myCombo);
      myCombo.attachEvent(‘onXLE’, function() {
         myCombo.selectOption(optionIndex);
      });
   });
});