Custom Lightbox Section - GetValue and SetValue

I have a custom lightbox section dealing with the date handling and do not use the normal time section.

I also use the MiniCal extension, and I have set the following config.

scheduler.config.full_day = true

In the onCreateEvent, I set ev.fullday = true because I don’t have a checkbox.

When I check ev.fullday in the SetValue of my custom lightbox section, it is correctly displayed as true, but if I check ev.fullday in the GetValue of my custom lightbox section it is undefined.

I thought that it will be part of the event object and accessible during the GetValue. Could something in the MiniCal extension be resetting it?

I stripped things back to basics to try and understand why this was happening, and I still get the error.

I used the 13_TouchUI sample as a starting point.

I added the following code.


			scheduler.form_blocks["customsection"] = {
				render:function(sns) {
					return "<div class='dhx_cal_ltext' style='height:60px;'>Custom Section</div>";
				},
				set_value:function(node, value, ev) {
					alert('SetValue  ev.fullday='+ev.fullday);
				},
				get_value:function(node, ev) {
					alert('GetValue ev.fullday='+ev.fullday);
					return;
				},
				focus:function(node) {
				}
			};
			scheduler.config.lightbox.sections = [
				{ name:"description", height:200, map_to:"text", type:"textarea" , focus:true },
				{ name:"mysection", height:72, type:"customsection", map_to:"auto" }
			];
		

I also have a button that calls

scheduler.addEventNow({ fullday: true });

The alert in set_value displays “SetValue ev.fullday=true”

The alert in get_value displays “GetValue ev.fullday=undefined”

Can you explain why ev.fullday is undefined in the get_value?

Schedulre itself doesn’t set ev.fullday in any scenario ( even when fullday checkbox is enabled, its value affects start and end dates only )

Most probably you have a custom section which has map_to:“fullday”, but its get_value doesn’t return anything. Scheduler will set result of get_value to property configured by “map_to”, if get_value returns nothing - it will result in “undefined” value.

I don’t have any inputs for fullday that the get_value could be taking it from.

If I set the value of ev.fullday using the following code, shouldn’t it be part of the ev object and persist and therefore be available in the get_value function of my custom section?

            scheduler.addEventNow({
               fullday: true
            });

If you look at the snippets that I provided above, you will see that there is no reference to fullday that get_value could be taking from.

As the function is defined as

get_value:function(node, ev)

shouldn’t ev contain all the event object properties?

If not, what is ev supposed to be?

Here’s how I thought things must operate.

Lightbox is called and each of the various sections’ set_value are called to populate the correct values into the input elements.

When the SAVE button is pressed, each of the various sections’ get_value are called and whatever code is present in each of the get_value functions is run, so, in the get_value, we can use custom code to move values from the inputs to the event object (ev)

Could you correct me if I have misunderstood the process?

Just to be certain, I have made sure that I do not have map_to:“auto”

This is the contents of the lightbox sections on my test page.

scheduler.config.lightbox.sections = [
	{ name:"description", height:200, map_to:"text", type:"textarea" , focus:true },
	{ name:"mysection", height:72, type:"customsection" },
];		

If you need it, I can provide a test page for you.

I did some more testing.

I added some additional testing by adding the extra fields that are defined in the documentation for addEventNow.

So, I am now creating the following

scheduler.addEventNow({
	start_date: new Date(2011,5,13,15),
	end_date: new Date(2011,5,13,18),
	text: "My new event",
	custom_data: "some data",
	mycustomvalue: "dhtmlx",
	fullday: true
});

in set_value of my custom section, I can access ALL of the properties of the ev object (see image 1 below)

in get_value of my custom section, I can access NONE of the properties of the ev object EXCEPT ev.text which is the only event property which has a corresponding INPUT on the lightbox. (see image 2 below)

So, it seems that in get_value it is only possible to access ev properties that have corresponding inputs on screen. Is that correct?



Actually not, while set_value contains full event object, in getter it is not guaranteed. It just an object on which you can set custom attributes which will be later transfered on event ( you can think about it as write-only event object )

so, in the get_value, we can use custom code to move values from the inputs to the event object (ev)

That is right, but you can only write values to that ev object, reading from it not reliable.
If you need to have some logic which must work with results from different sections, you can store each section through get_value and use login in onEventSave handler to produce combined value.

Thanks for letting me know, Stanislav.

Now that I’m aware of the limitation in get_value I can change my coding accordingly.

Hi Stanislav,

When changing my code, I think I have discovered a similar situation with the onEventSave.

onEventSave is defined as follows

scheduler.attachEvent(“onEventSave”,function(id,data,is_new_event)

Am I correct in assuming that the data object is the “write-only” event object that is also available via ev of the get_value functions of the lightbox sections?

So to check the current value of a custom_event_property that has NOT been part of the lightbox, I must use the id parameter and do scheduler.getEvent(id).custom_event_property to get the value?

For any properties that have been set via the lightbox, I will be able to get them by data.custom_event_property_set_in_lightbox

Something like

scheduler.attachEvent("onEventSave",function(id,data,is_new_event){
	// get an event property NOT USED in lightbox
	var custom_value1 = scheduler.getEvent(id).custom_event_property;
	// get an event property USED in lightbox
	var custom_value2 = data.custom_event_property_set_in_lightbox;
}

Also, the various properties of the data object will be merged into the ev object after the onEventSave

Am I correct in my assumptions?

Follow-up question

Is it possible to remove properties from the data object in the onEventSave to avoid them being sent to the server?

For example, I might have properties from my lightbox for First_Name and Last_Name and then in onEventSave do

data.Client_Name = data.First_Name + ' ' + data.Last_Name;

then I’d only want Client_Name POSTed to the server and not have First_Name and Last_Name being POSTed to the server.

Is that possible?

I’ve tried setting the unwanted properties to null or to blank, but they still get POSTed.

In onEventSave you can have something like

scheduler.attachEvent("onEventSave", function(id, data, isNew){ var event = scheduler.getEvent(id); delete data.First_Name; delete event.FirstName; //optional, see below ... });

data - event object constructed from the lightbox editors
event - original event object, it still not modified in this moment of time

If original event objects doesn’t have FirstName field, you need only delete custom property from data object.

Perfect.

Thanks for your help.

Sorry for reviving an old topic, but I think this is actually a bug which still exists. The event passed into GetValue is an empty object when really it should be the event in question. In the dhtmlxscheduler.js file there is the following function definition:
scheduler.save_lightbox = function () { var e = this._lightbox_out({}, this._lame_copy( this.getEvent(this._lightbox_id)));...

You’ll notice that _lightbox_out is being called with 2 arguments (an empty object and the result of a call to _lame_copy) and the call to _lame_copy with a single argument. However the function _lightbox_out only accepts one argument, whereas _lame_copy requires 2 arguments (copying the properties of one to the other).

I think the intent of the code is to call _lightbox_out with a copy of the event (rather than a reference to it). This object is what gets passed into GetValue. Because it is an empty object currently, that is why the event properties are not available. If the code were changed to:

scheduler.save_lightbox = function () { var e = this._lightbox_out(this._lame_copy({},  this.getEvent(this._lightbox_id)));...

then all works beautifully - you have your event properties (and when you the onEventSave function is called, your properties have not mysteriously reverted which they do currently!).