Lightbox Select Ajax

Hello

I’m trying to set a select options by ajax before open the light box but it doesn’t work.
I would like to change dinamically the options of the lightbox select, but the options don’t change.
This is my code:

//DEFAULT alert_opts
var alert_opts = [
		    { key: 1, label: 'None' },
		    { key: 2, label: 'On start date' },
		    { key: 3, label: '1 day before' }
		];
scheduler.attachEvent("onBeforeLightbox", function (id){
		alert_opts="";
		val=scheduler.getEvent(id);
		$.ajax({
                url: "<?php echo CfgRoot; ?>/modules/planning/planning.php?mode=getProjects",
                type: "POST",
                dataType: "json",
                async: false,
                data: {iduser:val.section_id},
                success : function(result){
                	// alert_opts=result.projectos;
                	var alert_opts = [
					    { key: 1, label: 'Test1' },
					    { key: 2, label: 'Test2' },
					    { key: 3, label: 'Test3' }
			];
                }
         });
	return true;
});

scheduler.config.lightbox.sections=[	
	{name:"description", height:130, map_to:"text", type:"textarea" , focus:true},
	{name:"Projectos", height:40, map_to:"alert_opts", type:"select", options:alert_opts},			
	{name:"time", height:72, type:"time", map_to:"auto"}
]

Or in a easy way, I would like to do something like this:

var alert_opts = [
		    { key: 1, label: 'None' },
		    { key: 2, label: 'On start date' },
		    { key: 3, label: '1 day before' }
		];

scheduler.attachEvent("onBeforeLightbox", function (id){
               var alert_opts = [
                         { key: 1, label: 'Test1' },
                         { key: 2, label: 'Test2' },
                         { key: 3, label: 'Test3' }
		];
                return true;
 }

scheduler.config.lightbox.sections=[	
	{name:"description", height:130, map_to:"text", type:"textarea" , focus:true},
	{name:"Projectos", height:40, map_to:"alert_opts", type:"select", options:alert_opts},			
	{name:"time", height:72, type:"time", map_to:"auto"}
]

Hello.

Your code doesn’t work because you’re just setting new array to “alert_opts” instead of replacing current one.
You could try to replace following:

success : function(result){
                   // alert_opts=result.projectos;
                   var alert_opts = [
                   { key: 1, label: 'Test1' },
                   { key: 2, label: 'Test2' },
                   { key: 3, label: 'Test3' }
         ];
}

with something like following.

success : function(result){
    alert_opts.splice(0, alert_opts);
    alert_opts.push.apply(alert_opts, result.projectos);
}

You could also get pretty same result if you’ll use serverLists and updateCollection. You could initialize your server list at app initialization and then update it with updateCollection when necessary. It also updates current array.
See articles:
docs.dhtmlx.com/gantt/api__gantt_serverlist.html
docs.dhtmlx.com/gantt/api__gantt … ction.html