Reputation: 1688
I've got a Kendo Grid using a custom popup editor. One of the fields is a Kendo dropdownlist which uses a remote datasource.
When a user makes a selection the data associated with the selected item is used to update a couple of the other fields in the popup editor using model.set
.
This is working well: the model and the field are updated.
However, if I then add required validationMessage="This field is required"
to the fields being updated by model.set
the validation error is triggered and the fields are not updated.
I've setup a JSFiddle to demonstrate the problem. In this case, the ProductName in the custom popup editor can be set by clicking the Set Product
button. You'll notice the validation error is triggered, but if you remove the required
attribute from the field it is updated correctly.
Is this a bug? Why is the validation error being triggered when the value is being set?
Edit: just to clarify -- this is when adding new records, not editing existing ones.
Upvotes: 2
Views: 9397
Reputation: 40917
When you assign a value to ProductName
you are actually losing focus from the input
, that triggers the validation and makes it complain about leaving it empty.
The solution would be assigning first the value to the input
and then do the set
.
var win = $(this).closest("[data-role=window]");
var uid = win.data("uid");
var input = $("[name='ProductName']", win);
// Assign value (anything works)
input.val("Test Product");
var model = $("#grid").data("kendoGrid").dataSource.getByUid(uid);
model.set('ProductName','Test Product');
Your Fiddle modified here : http://jsfiddle.net/OnaBai/ZPuS8/8/
Upvotes: 9