Model ID in template

2 posts, 1 answers
  1. Daniel
    Daniel avatar
    5 posts
    Member since:
    Dec 2012

    Posted 30 Dec 2013 Link to this post

    Hi everyone,

    I am facing a very interesting problem. I want to create a simple Todo app with DataSource and templating engine. ( I dont want to using Grid yet. )
    The ID of my model is TODOID (I am using oracle db with open access.) I want to use this id field in the template. It works properly until I want to add a new Todo Item. For example:
    $("#add-button").click(function () {
            dataSource.add({
                "TITLE": "asd",
                "PRIORITY": 3,
                "DEADLINE": "2013-02-02",
                "DONE": false
            });
     
            dataSource.sync();
        });
    In that case, I get an error: "ReferenceError: TODOID is not defined". But if I include the TODOID field as well (e.g "TODOID": 100) then my create method is not being called. It is called only when I dont include the id field in new todo item AND I am not using that field in the template. But I have to use the TODOID field in the template to able to modify or delete and select an item.

    So, how can i add a new todo item to the datasource without the reference error but also being able to select a single item in the UI?
    Or I am doing it the wrong way and I have to use Grid?

    Thank you for your answers,
    Daniel
  2. Answer
    Daniel
    Daniel avatar
    5 posts
    Member since:
    Dec 2012

    Posted 30 Dec 2013 Link to this post

    Hello,

    This error happens probably because you are using the TODOID field somewhere and it isn't defined for a new item (inserted via the add method). The workaround is simple - add a defaultValue setting for that field in your data source declaration:

    schema: {
        model: {
             id: "TODOID",
             fields: {
                 "TODOID": { defaultValue: 0 },
                  /* rest of configuration */
             }
        }
    }


    Regards,
    Atanas Korchev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top