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

Create submit 0 or null as field value

1 Answer 119 Views
Grid
This is a migrated thread and some comments may be shown as answers.
MiracleMan
Top achievements
Rank 1
MiracleMan asked on 05 Oct 2015, 02:37 PM

Hello all, 

I have grid which displays a group of records.  Then some custom actions to perform on this records. One of the custom actions will open a popup window which displays another grid with child information about the original table.  I'm doing this by passing a custom query string with the parent key.

 In this child table, when I try to create a new record, the foreign key that is passing to the controller is 0 event though when editing, the binding will show the correct value. Through jquery I'm able to read the parentID and put it in a hidden field in the child screen, but when submitting, is goes as 0 again even though it has a number on it.  The only way I'm able to solve the issue is by passing a value directly to the model in the child window in the OnEdit event like this:

 

    e.model.set("GroupID", $("#txtGroupID").val());

 

Anyone knows why is passing a 0 value although I'm assigning a value for it: $("#GroupID").val($("#txtGroupID").val());

Any recommendations?

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 07 Oct 2015, 08:34 AM

Hello MiracleMan,

 

The behavior you have described is caused by the fact that setting value via JavaScript to an input element will not trigger its change event. As you know the grid's edit form is bound to the model instance via our MVVM, which tracks user input to the UI elements by handling the appropriate change events. In this case the binder is not notified and the value which you have set to the element is not set into the model - this is why when pushed to the server, value is not the one you have set manually.

 

In order to correct this you should either use the set method of the model (as you have already mentioned) or manually trigger the change event of the input element (note that this element should have the appropriate data-binding attribute set).

$("#GroupID").val($("#txtGroupID").val()).trigger("change");

 

Regards,
Rosen
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
Grid
Asked by
MiracleMan
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or