clear text field after submission

This commit is contained in:
Ari Lazier 2015-09-01 16:19:02 -07:00
parent 44ab6d33ed
commit f69a9a45e6
2 changed files with 14 additions and 10 deletions

View File

@ -41,16 +41,18 @@ function updateItems() {
var todos = realm().objects("Todo"); var todos = realm().objects("Todo");
for (var todo in todos) { for (var todo in todos) {
itemsHTML += "<div class='todoContainer'><div class='todoItem'>" + todos[todo].text + itemsHTML += "<div class='todoContainer'><div class='todoItem'>" + todos[todo].text +
"</div><button class='deleteButton' onclick='deleteTodo(" + todo + ");'>complete</button></div>"; "</div><button class='deleteButton' onclick='deleteTodo(" + todo + ");'>Complete</button></div>";
} }
var items = document.getElementById('items'); var items = document.getElementById('items');
items.innerHTML = itemsHTML; items.innerHTML = itemsHTML;
} }
function addTodo(todo) { function addTodo() {
realm().write(function() { realm().write(function() {
realm().create("Todo", [todo]); var input = document.getElementById('todoInput');
realm().create("Todo", [input.value]);
input.value = "";
}); });
updateItems(); updateItems();
} }
@ -74,12 +76,12 @@ var app = {
onDeviceReady: function() { onDeviceReady: function() {
app.receivedEvent('deviceready'); app.receivedEvent('deviceready');
document.getElementById('todoButton').addEventListener('click', function() { document.getElementById('todoButton').addEventListener('click', function() {
addTodo(document.getElementById('todoInput').value); addTodo();
return false; return false;
}.bind(this)); }.bind(this));
document.getElementById('todoInput').addEventListener('keypress', function(e) { document.getElementById('todoInput').addEventListener('keypress', function(e) {
if (e.keyCode == 13) { if (e.keyCode == 13) {
addTodo(document.getElementById('todoInput').value); addTodo();
} }
return false; return false;
}.bind(this)); }.bind(this));

View File

@ -41,16 +41,18 @@ function updateItems() {
var todos = realm().objects("Todo"); var todos = realm().objects("Todo");
for (var todo in todos) { for (var todo in todos) {
itemsHTML += "<div class='todoContainer'><div class='todoItem'>" + todos[todo].text + itemsHTML += "<div class='todoContainer'><div class='todoItem'>" + todos[todo].text +
"</div><button class='deleteButton' onclick='deleteTodo(" + todo + ");'>complete</button></div>"; "</div><button class='deleteButton' onclick='deleteTodo(" + todo + ");'>Complete</button></div>";
} }
var items = document.getElementById('items'); var items = document.getElementById('items');
items.innerHTML = itemsHTML; items.innerHTML = itemsHTML;
} }
function addTodo(todo) { function addTodo() {
realm().write(function() { realm().write(function() {
realm().create("Todo", [todo]); var input = document.getElementById('todoInput');
realm().create("Todo", [input.value]);
input.value = "";
}); });
updateItems(); updateItems();
} }
@ -74,12 +76,12 @@ var app = {
onDeviceReady: function() { onDeviceReady: function() {
app.receivedEvent('deviceready'); app.receivedEvent('deviceready');
document.getElementById('todoButton').addEventListener('click', function() { document.getElementById('todoButton').addEventListener('click', function() {
addTodo(document.getElementById('todoInput').value); addTodo();
return false; return false;
}.bind(this)); }.bind(this));
document.getElementById('todoInput').addEventListener('keypress', function(e) { document.getElementById('todoInput').addEventListener('keypress', function(e) {
if (e.keyCode == 13) { if (e.keyCode == 13) {
addTodo(document.getElementById('todoInput').value); addTodo();
} }
return false; return false;
}.bind(this)); }.bind(this));