Customize event onTemplatesReady - error after create

I add some fields into “event_text”

scheduler.attachEvent("onTemplatesReady", function(){ scheduler.templates.event_text=function(start,end,event){ return "<u>" + event.login_name + "</u><br><b>" + event.denominazione + "</b><br><i>" + event.text + "</i>"; } });

But, after create new event my fields “event.login_name” and “event.denominazione” have value “undefined”.
If I reload page all works and I see correct value.

How can I fix this problem? I’ve to move my function in different event?


Do you set event.login_name and event.denominazione when you create an event? By default new event has only event.text and it displays as expected:

If you set them in some way, perhaps you need to use updateEvent to render the updated event with these values. … event.html

How can I set my properties when I create an event?

“onEventSave” I have in ev object my custom field:

  • utente
  • cliente

I add this fields in lightbox, but what I want to display in “onTemplatesReady” are the label of these value:

  • utente(value) -> login_name(label)
  • cliente(value) -> denominazione(label)

In lightbox these custom fields are combobox (type: select):

{name: "Cliente", height: 30, map_to: "cliente", type: "select", options: scheduler.serverList("cliente")}, {name: "Utente", height: 30, map_to: "utente", type: "select", options: scheduler.serverList("utente")},

and I load it in .php:

[code] $list_clienti = new OptionsConnector($res, “MySQLi”);
$list_clienti->render_sql(“Select id as value, denominazione as label from clienti where id_azienda=”.$id_azienda." order by denominazione",“id”,“value,label”);

$list_utenti = new OptionsConnector($res, "MySQLi");
$list_utenti->render_sql("Select id as value, login_name as label from userprofile order by login_name","id","value,label");
$calendar = new schedulerConnector($res, "MySQLi");

$calendar->set_options(“cliente”, $list_clienti);
$calendar->set_options(“utente”, $list_utenti)

try setting default values from onEventCreated event … event.html
It’s called right after event instance is created either with dnd or double click and before any template is called.

scheduler.attachEvent("onEventCreated", function(id,e){ var event = scheduler.getEvent(id); event.denominazione = ""; event.login_name = ""; });

There’s another way?

In onEventCreated “ev” object have only “value”, but not “label”.
Only way will be go server-side, do another query and get label from my table with value selected. :frowning:

Nobody can help me? :frowning:

I think I misread your question at some point.

Firstly, if the question is about setting the default value for selects, it can be solved in following way -
Given that you have two combos

{name: "Cliente", height: 30, map_to: "cliente", type: "select", options: scheduler.serverList("cliente")}, {name: "Utente", height: 30, map_to: "utente", type: "select", options: scheduler.serverList("utente")},
and they are mapped to “cliente” and “utente” properties respectively. Options can be accessed via server list - so in order to set default option you can capture onEventCreated, get available options from serverList there and assign value of option you want as a default one to the event

[code]scheduler.attachEvent(“onEventCreated”, function(id,e){
var event = scheduler.getEvent(id);

// select first option by default
var cliente = scheduler.serverList(“cliente”);
event.clietne = cliente.length ? cliente[0].key : “”;

var utente = scheduler.serverList("utente");
event.utente = utente.length ? utente[0].key : "";

Next, if you want to have a label of selected option in event text, you need to define event_text or event_bar_text template, get value of selected option from event object, get all available options via server list, find option which id is assigned to event and use its label - e.g.

scheduler.templates.event_text = function(start, end, event){ var clients = scheduler.serverList("clients"); var client = clients.find(function(c){ return c.key == event.client_id}); if(client) return client.label; return ""; };
You can check this discussion for reference - … 14&start=0 - there is a link to the demo in my first reply, where templates do what’ve described above

All perfect! Many many thanks!
Now it works without problems