Hello
Within my editor for a scheduler I'm changing some values through an AJAX-call and apparantely this does not change the model since the update action is never fired when I press update. The update works fine if I change a model bound value. How can I manually set the model as dirty?
Do I do it in the success method for the AJAX call and how?
Basically I just need to trigger update wheter the model is changed or not.
/Jonas
9 Answers, 1 is accepted

The SchedulerEvent model will be marked as "dirty" if the model is updated using its set method. Thus the datasource will know that those models should be updated/created/deleted.
In order to assist you further, please send us a repro demo that shows your current approach. Thus we will be able to review it and advice you further.
Regards,
Georgi Krustev
Telerik

Hello Georgi
From my edit template I'm making an AJAX call to do some stuff and in the success method I added the set method and I can see that a value gets changed but the .Update is still not triggered when I press update.
$.ajax({
url:
"Home/updateBooking/"
,
data: {
TaskID: $(
"#TaskID"
).val(),
personId: $(
this
).attr(
'name'
),
bookingType: $(
this
).attr(
'bookingtype'
),
taskOperators: $(
'#taskOperators'
).val()
},
cache:
false
,
type:
"POST"
,
dataType:
"JSON"
,
context:
this
,
error:
function
(request, statusText, errorMessage) {
$(
'#flash-message-error'
).show();
$(
'#flash-message-error'
).fadeOut(3000);
},
success:
function
(data, textStatus, XMLHttpRequest) {
$(
'#taskOperators'
).val(data.taskOperators);
//Do some UI stuff
var
observable =
new
kendo.data.ObservableObject({ isChanged:
false
});
alert(observable.get(
"isChanged"
));
observable.set(
"isChanged"
,
true
);
// set the value
alert(observable.get(
"isChanged"
));
}
});
Is this the correct place to do it, or should I do it server side in the called action Home/updateBooking/?

Probably, I am missing something because the "set method" approach works fine for me. Check this Dojo demo for more details:
Could you modify it and demonstrate the erroneous behavior?
Regards,
Georgi Krustev
Telerik

Yes, the set method updates my hidden value correct, but this still doesn't trigger the update action, the form just closes when I press update and the task_Update action isn't triggered.
this is the hidden value in my viewmodel:
public
bool
isChanged {
get
;
set
; }
added to the form, like this:
@Html.HiddenFor(model => model.isChanged,
new
{ data_value_primitive =
"true"
})
and updated by AJAX like this:
success:
function
(data, textStatus, XMLHttpRequest) {
//Other stuff removed to focus on the set method
var
observable =
new
kendo.data.ObservableObject({ isChanged:
false
});
observable.set(
"isChanged"
,
true
);
// set the value
}
Is there a way to set the model as dirty in the action called by the AJAX case or is there a way to always trigger the update action for the update button regardless off if the model is "dirty" or nor?
This is the action I want triggered when I press update from the form regardless of if the model is seen as changed or not
.Update(update => update.Action(
"Task_Update"
,
"Home"
).Data(
"additionalInfo"
))
From the provided code it seems that you still trying to create new observable object and update it's fields - please note that the Scheduler does not know about this object and if you actually need to update the event object than you should use the approach shown by my colleague Georgi. If you experience difficulties implementing the suggested approach in your real project you can provide runnable example where the described behavior can be reproduced and I would be happy to advice you how to proceed.
Regards,
Vladimir Iliev
Telerik

Ok
I will have to take a closer look at this later on.
In the mean while as a work around, is there away to always trigger the update action?
I.e
.Update(update => update.Action(
"Task_Update"
,
"Home"
).Data(
"additionalInfo"
))
How can I make sure this call always gets made?
Can I override the built in update and write my own call to task_Update and how?
/Jonas
This behavior is not supported and it will require custom code - for example you can try using the Scheduler and it's DataSource events to make sure currently edited event have dirty flag set to "true".
Regards,
Vladimir Iliev
Telerik