This is a migrated thread and some comments may be shown as answers.

Set model as dirty from AJAX

9 Answers 289 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Jonas
Top achievements
Rank 1
Jonas asked on 12 Nov 2015, 08:38 AM

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

Sort by
0
Jonas
Top achievements
Rank 1
answered on 16 Nov 2015, 07:44 AM
No one has any idea?
0
Georgi Krustev
Telerik team
answered on 16 Nov 2015, 09:09 AM
Hello Jonas,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Jonas
Top achievements
Rank 1
answered on 16 Nov 2015, 09:35 AM

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/?

0
Jonas
Top achievements
Rank 1
answered on 16 Nov 2015, 11:24 AM
sorry about the double posts, I got an error message when I first tried to post and thought it didn't get through
0
Georgi Krustev
Telerik team
answered on 18 Nov 2015, 09:31 AM
Hello Jonas,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Jonas
Top achievements
Rank 1
answered on 18 Nov 2015, 12:45 PM

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"))
 

 

0
Vladimir Iliev
Telerik team
answered on 20 Nov 2015, 12:31 PM
Hello Jonas,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Jonas
Top achievements
Rank 1
answered on 23 Nov 2015, 09:35 AM

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

 

0
Vladimir Iliev
Telerik team
answered on 24 Nov 2015, 10:38 AM
Hi 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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Scheduler
Asked by
Jonas
Top achievements
Rank 1
Answers by
Jonas
Top achievements
Rank 1
Georgi Krustev
Telerik team
Vladimir Iliev
Telerik team
Share this question
or