Hi,
I am trying to call saveChanges from edit event
It seems to create a loop. Any suggestions how I could safely call saveChanges() ? Sample project
I am trying to call saveChanges from edit event
function
gridEdit(e) {
var
fieldName = e.container.find(
"input[name]"
).attr(
"name"
);
if
(fieldName) {
//new row validtaion
if
(e.model.isNew() && fieldName ==
"EntityName"
) {
var
validator = e.container.getKendoValidator();
var
options = validator.options;
options.rules.testRule =
function
(input) {
if
(input.is(
"[name='EntityName']"
) && input.val() !=
""
) {
$scope.kgrid.saveChanges();
}
return
true
;
}
options.messages.testRule =
"is not unique."
;
validator.setOptions(options);
}
}
}
It seems to create a loop. Any suggestions how I could safely call saveChanges() ? Sample project
6 Answers, 1 is accepted
0
Accepted
Hi Wit,
Calling the saveChanges method with a timeout should prevent the infinite loop. For example:
Regards,
Alexander Popov
Telerik
Calling the saveChanges method with a timeout should prevent the infinite loop. For example:
if
(input.is(
"[name='EntityName']"
) && input.val() !=
""
) {
setTimeout(
function
() {
$scope.kgrid.saveChanges();
});
}
Regards,
Alexander Popov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0

Wit
Top achievements
Rank 1
answered on 17 Oct 2014, 02:29 PM
Hi Alexander,
That looks great, the only problem is that my grid edit event is fired twice so I have two records created. Is that expected behaviour? Is there any workaround for it?
Thank you
That looks great, the only problem is that my grid edit event is fired twice so I have two records created. Is that expected behaviour? Is there any workaround for it?
Thank you
0
Hi Wit,
Generally speaking, manipulating data from withing the validation rules is not considered a good design. The validation should either permit or deny certain actions, not take actions itself, so I would suggest returning "false" if certain conditions are not met. This would allow the users to save the data as usual, but it will prevent them from doing so if the data is not matching the validation rules.
Regards,
Alexander Popov
Telerik
Generally speaking, manipulating data from withing the validation rules is not considered a good design. The validation should either permit or deny certain actions, not take actions itself, so I would suggest returning "false" if certain conditions are not met. This would allow the users to save the data as usual, but it will prevent them from doing so if the data is not matching the validation rules.
Regards,
Alexander Popov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0

Wit
Top achievements
Rank 1
answered on 21 Oct 2014, 12:30 PM
Hi Alexander,
I agree with you, but my requirement is to auto save the grid then certain conditions are meet. I would appreciate if you could recommend other way of doing it.
Thank you
I agree with you, but my requirement is to auto save the grid then certain conditions are meet. I would appreciate if you could recommend other way of doing it.
Thank you
0
Hello again Wit,
Closing the cell and calling the saveChanges method work as expected on my side, as seen in this screencast. Keep in mind that if the Create request did not succeed it will be sent again with the next call of the saveChanges method.
Regards,
Alexander Popov
Telerik
Closing the cell and calling the saveChanges method work as expected on my side, as seen in this screencast. Keep in mind that if the Create request did not succeed it will be sent again with the next call of the saveChanges method.
Regards,
Alexander Popov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0

Wit
Top achievements
Rank 1
answered on 23 Oct 2014, 09:18 AM
Thank you