Pending Review
Last Updated: 10 Sep 2019 08:47 by ADMIN
Muhammad
Created on: 23 Aug 2019 11:40
Category: Grid
Type: Bug Report
0
Unable to set model field in edit mode pragmatically using model.set
  1. Create a grid with two editable columns.
  2. Define validation rules for both columns. Keep one column as required.
  3. Edit the row. Set the required column value using model.set method.'

It fails because before setting the value it performs validation. If validation was successful then it will set the value on model.

Since the desired field has no value and validation rule will fail on that.

 

It should accept the value and then perform validation. If validation fails with new value then it might discard the changes.

 


$("#grid").kendoGrid({ dataSource: { batch: true, transport: { read: function(e){ e.success([1,2,3,4,5,6,7,8,9].map(function(i){return {id: i, title: "test" + i}})); } }, schema: { model: { id: "id", fields: { id: {defaultValue: "-1"}, title: { validation: { required: true } } } } } }, columns: [ {field: "title", title: "Title", filterable: {field: "title.a"}}, {command: ["edit", {name: "destroy"}]} ], editable: {mode: "inline"}, filterable: true, toolbar: [{name: "create"}] });

 

var grid = $("#grid").getKendoGrid();
var model = grid.dataItems()[0];
grid.editRow(model);
model.set('title', '');
model.set('title', 'test 1111'); // it will fail


 

Attached Files:
4 comments
ADMIN
Boyan Dimitrov
Posted on: 10 Sep 2019 08:47

Hello,

Thank you for the detailed information in your last response. 

Indeed for such cases we definitely suggest to either change the value of the input using the API methods of the Kendo UI widget or simply set the input value and trigger change. As you noted this will bound the new value to the new value with the model field. 

Since the model set method is part of the Kendo UI core functionality any change might cause some unexpected behavior in many scenarios.

Regards,


Boyan Dimitrov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
ADMIN
Preslav
Posted on: 06 Sep 2019 13:17

Hello Muhammad,

My name is Preslav, and I am stepping in for my colleague Boyan who is currently out of the office.

Thank you for the clarification of the scenario. Indeed, you have a point, and this behavior might be considered as a bug.

Having said that, I will discuss the above with my colleagues and I will come back to you here as soon as I have more information.

 

Regards,
Preslav
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Muhammad
Posted on: 31 Aug 2019 09:28

The required validation was just an example. There are other scenarios when one might face issues. I also have another scenario.

 

I have two fields on my model startDate & endDate.

I have a validation rule on endDate that it cannot be less than startDate.

I have a requirement that when user selects startDate greater than endDate then on change of startDate automatically set the endDate equal to next day of startDate.

 

Scenario:

  • User picks 2019-08-31 in startDate field
  • User picks 2019-09-01 in endDate field

Validation passes (Great).

  • User picks 2019-09-20 in startDate field
  • System attempts to set 2019-09-21 in endDate field (BUT VALUE DOES NOT CHANGE AND REMAINS 2019-09-01 and endDate validation message appears)

Since editor performs validation before setting the value

At this moment endDate is 2019-09-01 which is less than 2019-09-21. The validation for endDate fails and error message is shown under endDate control.

Editor does not proceed to set 2019-09-21 in endDate field.

There are multiple scenarios where it fails. Although bypassing the set event works as you mentioned but it generally does not feel a good idea when it happens in so many places in large applications.

 

As an alternative I set the value on endDate's input control and triggered it's change event. It ultimately bound the new value with model field. But I feel when I have model available then it is good to set value on model instead on input control because sometimes we have to do such things before the datepicker like widgets are initialized.

 

Rest is Kendo's decision whether is comes under it's business model or not to consider such issues for fixation.

ADMIN
Boyan Dimitrov
Posted on: 30 Aug 2019 11:33
Hello,

As far as I understand the problem here is that the model.set method allows you to set an empty string for a value of the field. The validation in the widget configuration is actually an UI validation. It is designed to react to user interaction and user input. The "required" UI validation should prevent user from trying to set an empty string to a specific field as input. The set method of the model is something different, because it is something that is done on purpose by the developer. 

If your goal is to be able to avoid facing the validation when set method of the model is used (the validation to work only when user interacts with the UI) is to remove the set event handler of the model as shown below: 

 
var set =   model._events.set;
delete model._events.set;
model.set('name', 'aa');
 
model._eventds.set = set;


Regards,
Boyan Dimitrov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.