In one of my models, I have a series of boolean values (that in turn handle values for checkboxes) where at least one has to be checked before being considered "valid". As I have not found a good way to handle that kind of validation directly in the model, I am manually checking those 3 booleans in the ActionResult and where all are false, I return an error on the ModelState.
What I would like to be able to do is when the grid receives the error in its respective event, to keep the row that was being edited in edit mode. My attempts to put the row in edit mode manually have not worked, as it appears a sync is firing, which triggers DataBound, which tromps all over my row that I just put into edit mode.
Is there a way to:
1. Instruct a grid to keep edit mode open (with the original values) when an Error event is triggered from a DataSource save?
or
2. Define a custom client-side validation step to perform the check against those booleans before the DataSource Save?
6 Answers, 1 is accepted
Preventing the Grid from exiting edit mode is not supported out of the box but can be achieved by using the approach from this code-library.
As for creating validation you could define a custom validation attribute (or just extend the Kendo validator)as demonstrated in the "Custom validator editing" demo in the offline examples project that is included with the installation. You could also use the Grid save event and use the event argument preventDefault method to prevent the data to be posted when there are invalid values.
Daniel
Telerik
It worked properly on that project, when I add the same code to my project this args.sender.options.table is null. I have args, sender and options, but table is null.
I guess it's something that changed in latests versions of Kendo. Is there any other way of doing that?
I have some Business validation rules on server side that may cause some exception that I add to ModelState and I want to keep edit mode open.
Thanks,
Ezequiel
The DataSource events no longer provide a reference to the Grid through the args.sender argument. You could however, get the Grid's instance manually. For example:
var
grid = $(
"#Grid"
).data(
"kendoGrid"
);
grid.table ...
.Events(events => events.Error(
"error_handler.bind({WidgetID: '#Products'})"
))
....
<script type=
"text/javascript"
>
function
error_handler(e) {
var
grid = $(
this
.WidgetID
).data(
"kendoGrid"
);
....
</script>
Regards,
Alexander Popov
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
So, for a basic and logical thing, our team will need to copy a function to every grid we have on our system?
I don't see any logic in not keeping in Edit Mode by default when the ModelState is invalid...
I am afraid that adding this functionality as built-in one is not currently planned. If you believe that this should be the default behavior then I can suggest to open a feature request in our user voice forum.
Regards,
Daniel
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.