Using a selector mapped for "text"

Hello,

I’m using a selector (pick a type of meeting) in the upper field of the light box mapped for “text”:

scheduler.config.lightbox.sections = [
    { name:"select", height:40, map_to:"text", type:"select", options:alert_opts, focus:true },
...

When a new event is validated the visible text in the day view is the index - a number, in my case- and not the option of the select field. But after refreshing, the sql table request runs and the event’s display become right- the number is replaced by the type of meeting.
How can I do for resolve it?

Thank you and sorry for my poor english…

I found the solution myself.

When a new event is added, it changes the text in case of numbers…
This is it:

scheduler.attachEvent("onEventAdded", function(id,ev){ if (scheduler.getEvent(id).text=='1'){ scheduler.getEvent(id).text = "<?php echo $tab_type_event[1]; ?>"; scheduler.updateEvent(id); }

thank’

Hi,
please consider managing event content using template functions, this is an expected approach for such cases.
Here is a demo:
docs.dhtmlx.com/scheduler/snippet/0ec4db06
related docs:
docs.dhtmlx.com/scheduler/api__s … plate.html
docs.dhtmlx.com/scheduler/api__s … plate.html
docs.dhtmlx.com/scheduler/api__s … rlist.html

Hello Aliaksandr.

That’s it!

But my problem is that the index is saved in the DB sql and not the label… That’s why I did a lot of changes to have label appearing in the text event and not the index…

Is there any more simple solutions?

Hello,
managing the templates is the simplest solution in case you want event descriptions to be defined by some other properties.
However, I think I don’t complete understand what your trying to do.

There may be three cases:

  1. You need to store option id in events table, text description is generated based on it and calculated from code.
    Event object stores an id of option it is binded to.
    Somewhere on the client side you have array of all available options. So template function displays a correct label for each section.

  2. You store option title in db in events table, option id is omited.
    If you don’t want to store id of selected option at all, and only need the label - you won’t need additional code (including templates), simply use option title as both key and label:
    options:[ {key: “Math”, label:“Math”}, …]

  3. You store both option id and option title
    If you need to store both - option title as event.text and option id as some other property of an event - you need to map select control to that property, and assign event.text from onEventSave event
    docs.dhtmlx.com/scheduler/api__s … event.html

I am in the first case.

But, I simply forget to change my sql command on connector.php

$schedulerConn->render_complex_sql("Select reunions.id as idreunion, reunions.type,reunions.start_date, reunions.end_date, reunions.ordreduj, typereunion.id, typereunion.type from reunions, typereunion  WHERE  reunions.type=typereunion.id",  "idreunion", "start_date,end_date,type,ordreduj");

TO

$schedulerConn->render_table("reunions","id","start_date,end_date,type");

Sorry and thank you for patience…

Hello.

After week off, coming back with my last non solution…
I followed the previous consulting but I dont understand why the “type” (as an ‘id’ int) of the meeting is not saved in my sql DB with the field ‘subject’ mapped to ‘text’…

Do you have any idea?

This is my code:


scheduler.init("scheduler_here",new Date(),"month");	

scheduler.serverList("options", [
  	{ key: 0, label: 'Choisissez' }
   <?php
   $i=1; 
   while (!($i>$last_id)) { 
   	echo ",{ key: ".$i.", label: '".$tab_type_event[$i]."' }"; 
   	$i++;
   }
   ?>]);

scheduler.config.lightbox.sections=[
	{name:"subject", height:20, type:"select", map_to:"text",options: scheduler.serverList("options"), focus:true },
	{ name:"odj", height:50, map_to:"type", type:"textarea"},
    { name:"time", height:72, type:"calendar_time", map_to:"auto"}
];
	

// input  DB SQL
	var idhg="<?php echo $_SESSION['nomhg']; ?>";
	scheduler.load("dhtmlxschedulerv4/codebase/connector.php?idhg="+idhg);
	//scheduler.load("dhtmlxschedulerv4/codebase/connector/data_db.php");

// OUtput DB SQL
	var dp = new dataProcessor("dhtmlxschedulerv4/codebase/connector.php?idhg="+idhg);
	dp.init(scheduler);


(function(){

	var optionsHash = null;

	function buildSearch(){
        // build hash with options to speed up search in case huge amount of events/options
		optionsHash = {};
		var list = scheduler.serverList("options");
		for(var i = 0; i < list.length; i++){
			optionsHash[list[i].key] = list[i].label;
		}
	}
  
	scheduler.attachEvent("onOptionsLoad", function(){
		optionsHash = null;
	});
  
	function getLabel(optionId){
		if(!optionsHash) buildSearch();

		return optionsHash[optionId] || "";
	}

    // text content of events in day/week/units views
	scheduler.templates.event_text = function(start, end, ev){
		return getLabel(ev.text);
	};
    // text content of events in month/timeline views
	scheduler.templates.event_bar_text = function(start, end, ev){
		return getLabel(ev.text);
		
	}
})();

and my connector:

[code]<?php
require_once(“connector/scheduler_connector.php”);

$base=‘xxxxx’.$_GET[‘idhg’];
$res= mysql_pconnect(“xxxxx”, “xxxxx”, “xxxxx”) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($base);

$schedulerConn = new SchedulerConnector($res);

$schedulerConn->render_table(“reunions”,“id”,“start_date,end_date,type,ordreduj”);
[/code]

I forget to say that the array filing is ok so the select is running correctly.
Saving the event displays the correct event name.
The event is saved on the sql db.
But after refreshing the event text is first position of the array.
The value saved is 0 (default for de table).

Thank you

The problem is coming from the line

{ name:"odj", height:50, map_to:"type", type:"textarea"},

in the lightbox controle: scheduler.config.lightbox.sections.

I don’t find in the documentation the way to use a text field and sending it in the DB… but I continue the search…

Ok, it wasn’t easy to find that de map_to:"" can have any name used for sql column name in the connector.

Thank’s for your teaching silence…