From f69a9a45e62a2cd063d2256e36e08635bf93cfa4 Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Tue, 1 Sep 2015 16:19:02 -0700 Subject: [PATCH] clear text field after submission --- examples/cordova/platforms/ios/www/js/index.js | 12 +++++++----- examples/cordova/www/js/index.js | 12 +++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/examples/cordova/platforms/ios/www/js/index.js b/examples/cordova/platforms/ios/www/js/index.js index 7ea98511..ed3c765d 100644 --- a/examples/cordova/platforms/ios/www/js/index.js +++ b/examples/cordova/platforms/ios/www/js/index.js @@ -41,16 +41,18 @@ function updateItems() { var todos = realm().objects("Todo"); for (var todo in todos) { itemsHTML += "
" + todos[todo].text + - "
"; + ""; } var items = document.getElementById('items'); items.innerHTML = itemsHTML; } -function addTodo(todo) { +function addTodo() { realm().write(function() { - realm().create("Todo", [todo]); + var input = document.getElementById('todoInput'); + realm().create("Todo", [input.value]); + input.value = ""; }); updateItems(); } @@ -74,12 +76,12 @@ var app = { onDeviceReady: function() { app.receivedEvent('deviceready'); document.getElementById('todoButton').addEventListener('click', function() { - addTodo(document.getElementById('todoInput').value); + addTodo(); return false; }.bind(this)); document.getElementById('todoInput').addEventListener('keypress', function(e) { if (e.keyCode == 13) { - addTodo(document.getElementById('todoInput').value); + addTodo(); } return false; }.bind(this)); diff --git a/examples/cordova/www/js/index.js b/examples/cordova/www/js/index.js index 7ea98511..ed3c765d 100644 --- a/examples/cordova/www/js/index.js +++ b/examples/cordova/www/js/index.js @@ -41,16 +41,18 @@ function updateItems() { var todos = realm().objects("Todo"); for (var todo in todos) { itemsHTML += "
" + todos[todo].text + - "
"; + ""; } var items = document.getElementById('items'); items.innerHTML = itemsHTML; } -function addTodo(todo) { +function addTodo() { realm().write(function() { - realm().create("Todo", [todo]); + var input = document.getElementById('todoInput'); + realm().create("Todo", [input.value]); + input.value = ""; }); updateItems(); } @@ -74,12 +76,12 @@ var app = { onDeviceReady: function() { app.receivedEvent('deviceready'); document.getElementById('todoButton').addEventListener('click', function() { - addTodo(document.getElementById('todoInput').value); + addTodo(); return false; }.bind(this)); document.getElementById('todoInput').addEventListener('keypress', function(e) { if (e.keyCode == 13) { - addTodo(document.getElementById('todoInput').value); + addTodo(); } return false; }.bind(this));