Server side validator and custom detail form errors


This time, a question related to processor logic and form.

I introduce you the context :
I have a custom detail form, opened in

scheduler.showLightbox = function(id){}

However, I do not use scheduler.startLightbox() in it or scheduler.endLightbox() in my custom save function because :

  • I have no #custom_form html container on the page : in fact, I call with AJAX a detail form which needs to be generated server-side (more server logic, form specific to type of event, …)
  • I use another lightbox system, which (like component one) loads the form in current document (no iFrame so).

When I click on “SAVE”, “CANCEL”, or “DELETE” button on my custom form, I call custom JS function. In my custom “SAVE” method, I populate the ev object then call the :

_edit_stop_event(ev, true);
// then I close my custom detail form (and its lightbox)

This methods calls my custom server side logic to create or update the event, returning the waited XML <action type="" <id…>>

The issue I meet : I can not use all validators on client side, so you understand : my server side logic check some data not tested client side and need in some case to return a : “The event can not be updated, please check your inputs”, but how could I do that ? the _edit_stop_event() return no value, so I can not know if I need to close my detail form or if I need to display error messages to the user without closing my detail form so that he can update its input before trying to save again.

Maybe in my save function I just need to call the _edit_stop_event(), and use another event listener to know if retrieve XML action/type is an “error” or not, so that I can eitgher close the form or display errors in it ?

If it is easier to implement, I could come back to native system, by calling my custom form with Ajax in a first time to put in HTML document then using scheduler.<show|end>Lightbox() to opening it in existing component lightbox. But even with native system I’m not sure that there is a way to do server side validators and permits to keep detail opened to allows user to keep on its edition…

(I hope this message is enough comprehensible…)

If you are using default saving logic - it is async, which means the _edit_stop_event can’t return anything, as server side logic not really processed yet ( it is in progress )

You can have something like

dp.attachEvent("onAfterUpdate", function(sid, action, tid, tag){ if (action == "error" || action == "invalid" ) show_some_message(); else // all is fine scheduler.hide_lightbox(); //or your custom code for lightbox hiding });

Now for data saving you can call _edit_stop_event which will send data to server side and data saving callback will trigger onAfterUpdate which will close editor or show message about validation error.

Hi Stanislav,

Perfect, that works like a charm.

I think the async process is lost so, because the detail form stays opened until onAfterUpdate event trigerring. In this way, if we are not in an auto-update or if server side processing is a bit long or connection a bit slow then the user can not start to edit another event as long as the previous response is not come back.
There is probably a way to work around a system which would backup the input (or hide the form) until the response comes and allow the system to re-open the form (if there are errors) or close it.

Thanks for the solution.

Hi again,

Just a question about this “onAfterUpdate” event : there is no way to rollback the done behaviour ?
I explain : if I edit an event in custom form and change the start_date then send back a “data/action@type=error” of the event SID, visually the event has been moved. Even when I do a drag&drop, the event is moved where as the data action is of type “error”.
So I need to reload the page to see the real state of my events.

To make explicit, the final goal would be this one : be able after server side process,

  • either to accept the modifications (by drag&drop or by edition) if saving is OK,
  • either, if errors, rollback :
    [list][*]the drag&drop (the even returns to its previous datetime)
  • or keep opened the detail form while editing to notice the user of errors (if the user chooses to cancel the form instead doing editings, the even returns to its previous state (=datetime + data)).
    Maybe onAfterUpdate is not the better event to deal with this behaviour ?
    I’ve tried, but not to avail, kind of instructions : scheduler.<render_view_data|update_view)() or dp._need_update = true; return false;
    (One thing it’s sure, I need to understand the whole process from A to Z and perhaps it would be completely obvious).

I thought about adding a custom validator on a “before save event” which would call server side, but we can not be sure that the saving action would be a success (an issue can occur) even if before save validation was OK.

If someone can enlighten me about this “validation/rollback/keep on editing”, if native or semi-native, thanks.

There is no rollback, as scheduler doesn’t store original event
You can do the next

  • before calling the saving logic, store the copy of event

var backup_events = {}; //global var ... backup_events[] = { start_date:new Date(ev.start_date), end_date:new Date(ev.end_date), text:ev.text }; scheduler._edit_stop_event(ev, true);

later from onAfterUpdate, if you have error status you can use

var ev = scheduler.getEvent(id); ev.text = backup_events[id].text; ev.start_date = backup_events[id].start_date; ev.end_date = backup_events[id].end_date; dp.setUpdated(id, false); //remove updated status from event scheduler.updateEvent(id); //repaint event

Also, you can add one more line to above code, which will open editor again.

Hi Stanislav, thanks for advices, I will work to this effect.
The component flexibilty is very great.