Handling the "set" event of model cancels grid "save" event

12 posts, 0 answers
  1. Todd
    Todd avatar
    26 posts
    Member since:
    Sep 2012

    Posted 26 Aug 2012 Link to this post

    Kendo.web.min  v2012.2.710

    Is handling the set event of the data-model supposed to prevent the grid's save event from firing??  It does for me.  See here:  http://jsfiddle.net/hvzw7/

    Commenting out the set event will allow the save event to fire.

    Also, the set event's parameters appear to be 2 separate parameters: the field and the field's value, but the documentation states one parameter with 2 properties (e.field and e.value).
  2. Todd
    Todd avatar
    26 posts
    Member since:
    Sep 2012

    Posted 06 Sep 2012 Link to this post

    Is this intentional ?
  3. Kendo UI is VS 2017 Ready
  4. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 12 Sep 2012 Link to this post

    Hello Todd,

    The Grid save event will not fire because when handling the set function of the model the record is not marked as dirty and the change event is not raised. You should either use the default function or perform the same actions in order for the values to be saved.

    Kind regards,
    Daniel
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  5. Todd
    Todd avatar
    26 posts
    Member since:
    Sep 2012

    Posted 12 Sep 2012 Link to this post

    Thanks Daniel, that makes sense.  Using the model's "set" method will still update the grid's cells, so the save event is only when you made the changes using the grid.

    What about the documentation discrepancy I mentioned??

    Thanks.
  6. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 17 Sep 2012 Link to this post

    Hello Todd,

    When specifying the set option to the model, you will override the function instead of binding to the "set" event. In order to bind to the event of the observable object you should use code after loading data or in the Grid edit event in this case. For convenience I updated the jsFiddle sample to show the second approach.

    Regards,
    Daniel
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  7. Todd
    Todd avatar
    26 posts
    Member since:
    Sep 2012

    Posted 17 Sep 2012 Link to this post

    Daniel,

    Thanks for posting a workaround, but you still haven't answered my question about the documentation discrepancy.  Please answer.  See my first post for details.
  8. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 20 Sep 2012 Link to this post

    Hello Todd,

    I am not sure if I understand correctly the problem with the documentation. The set event of the observable object receives a single parameter which has fields field and value. The set method accepts two parameters the field name and the value. Could you specify where in the documentation it is stated that the set event has two parameters?

    Regards,
    Daniel
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  9. Todd
    Todd avatar
    26 posts
    Member since:
    Sep 2012

    Posted 20 Sep 2012 Link to this post

    I used the wrong term "parameters"...I meant "arguments"....the arguments the set event receives when fired.

    http://docs.kendoui.com/api/framework/observableobject#set-event

    Under the "Event Data" section of the "Set Event", you see e.field, e.value  ...but the event actually receives 2 different arguments, not 1 argument with 2 properties.  Please see here for proof:

    http://jsfiddle.net/hvzw7/

    In this jsFiddle, change the product name cell value to something like "cat", and the set event fires, where you can see the 2 different arguments (not one argument "e" with 2 properties).
  10. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 22 Sep 2012 Link to this post

    Hello again Todd,

    As in one of my previous replies I can say, that when specifying the set option to the model like in the jsFiddle sample:

    model: {
       set: function(field, fieldValue) {
           log.append('<br />(model set) ' + field + ':  ' + fieldValue);  
       }
    you will not bind to the set event but you will override the set method which accepts two parameters.  Regards,
    Daniel
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  11. Remco
    Remco avatar
    31 posts
    Member since:
    Sep 2012

    Posted 08 Nov 2012 Link to this post

    I assume it's ok to override the set method as long as you call the base set method like so:
    kendo.data.ObservableObject.fn.set.call(this, name, value); 

    correct? Being able to override the set method is better than handling your own change event.
  12. Josh
    Josh avatar
    72 posts
    Member since:
    Jun 2013

    Posted 01 Dec 2014 in reply to Remco Link to this post

    Is Remco's suggested way to override the set method on an observable an accepted practice or something to avoid?

    set: function (name, value) {
        if (name === "stuff") { value = "foo bar"; }
        kendo.data.ObservableObject.fn.set.call(this, name, value);
    }
  13. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 04 Dec 2014 Link to this post

    Hello,

    We haven't recommended this approach but it is a possible solution.

    Regards,
    Daniel
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top
Kendo UI is VS 2017 Ready