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

Model ID in template

1 Answer 73 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 30 Dec 2013, 10:39 AM
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

1 Answer, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 30 Dec 2013, 01:13 PM
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!
Tags
General Discussions
Asked by
Daniel
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or