In MVC, scheduler.net, I am using addEvent (onclick) to add event on the fly. I added onEventSave for validation purposes, which is triggered by addEvent.
onEventSave, actually makes a json call to the controller and return a bValid. and based on that bValid, i decide to return true or false from onEventSave.
My undertsanding is that, If I return false from onEventSave than no further processing (saving is done) on the server side.
However, the problem is that on the client side view the event already is added.
What should I do, if I want the server validation to precede the client side addEvent ?
If you want to do server side validation from that event, you need to use sync. ajax call, to block js execution, while awaiting for result from server side.
By design, it is expected that you will have validation code as part of data saving handler, while it can’t block client side editor closing, it can return info about failed validation to client side, where some kind of message can be show.
Hi,
“onEventAdded” doesn’t allow to cancel event creation. You can validate event right inside the Save action, and after that process response using “onAfterUpdate” action of the dataprocessor.
server:public ContentResult Save(int? id, FormCollection actionValues)
{
var action = new DataAction(actionValues);
....
switch (action.Type)
{
case DataActionTypes.Insert:
//validate it somehow
if(isInvalid){
action.Type = DataActionTypes.Error;
action.Message = "Invalid event";
}else{
data.Events.InsertOnSubmit(changedEvent);
}
break;
....
}
return (new AjaxSaveResponse(action));
}client:scheduler.dataProcessor.attachEvent("onAfterUpdate", function (sid, action, tid, tag) {
if (action == "error") {
scheduler.deleteEvent(sid, true);
dhtmlx.message(tag.textContent);//show action.Message
}
})
thank you Stanislav, thank you Aliaksandr,
The code snippets that you posted were exactly what I needed.
It got me moving forward with working on my validation.
I still have one issue.
It seems that i can run scheduler.addEvent(…) only once. If i refresh my view, i get it to work once, not more.
All subsequent call will not get to save in the controller.
Is it an ajax related issue ?
Is it cash related ?
Is there any way to refresh things withe very call ?
The above mentioned solution is working for default save and drag and drop updates to an appointment. How do we do it for CustomLightBox save. Any onAfterUpdate event is not getting triggered when we use CustomLightBox. Could you please let us know a work around to trigger onAfterUpdate triggering for CustomLightBox please
Hello,
sorry for the delay.
We’ve confirmed the issue, the component do not send a Message to the client side. Fix will be available by the end of the week