When i try to add the object to the objectStore with .add, the console shows this error: DataError: Data provided to an operation does not meet requirements. If someone can tell where this error came from it will really help me. This is the code:
var request = objStore.add({tarea: todo, clase: "pendiente"});
var db;
function create_to_do(){
var todo = document.querySelector('#the-do').value;
var transaction = db.transaction("to_do", "readwrite");
transaction.oncomplete = function(eve){
console.log("all done¡")
}
transaction.onerror= function(eve){
console.log("something went wrong: "+ eve.target.errorCode);
};
var objStore = transaction.objectStore("to_do");
var request = objStore.add({tarea: todo, clase: "pendiente"});
request.onsuccess = function(eve){
console.log("all done¡");
console.log(eve.target.result);
};
}
function indexDB(){
var request = indexedDB.open('todos', 1);
request.onsuccess = function (evt) {
db = this.result;
console.log("Database Opened");
};
request.onerror = function (evt){
console.log("OpenDB error: " + evt.target.errorCode);
};
request.onupgradeneeded = function(evt){
store = evt.currentTarget.result.createObjectStore("to_do",
{keyPath: 'id', autoIncrement: true});
store.createIndex('clase', 'clase', {unique: false});
console.log("index created");
};
}