Skip to content

Commit

Permalink
very very basic validation
Browse files Browse the repository at this point in the history
  • Loading branch information
addyosmani committed Feb 9, 2012
1 parent fa1ca32 commit 644c337
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 15 deletions.
1 change: 1 addition & 0 deletions css/todo.css
Original file line number Diff line number Diff line change
Expand Up @@ -533,3 +533,4 @@ select,
border-radius: 3px;
}


5 changes: 5 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<button class="btn">Add</button>
</div>

<div id="error">
<div id="alert">

</div>
</div>
<div id="todo-list">
<ul></ul>
</div>
Expand Down
61 changes: 46 additions & 15 deletions js/modules/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ app.core.define('#todo-counter', function(f){
counter = f.find('#count')[0];
f.subscribe({
'new-entry' : this.updateCounter
})
});

},
destroy:function(){
counter = null;
Expand Down Expand Up @@ -88,6 +89,27 @@ app.core.define('#todo-entry', function(f){



app.core.define('#error', function(f){
var errorHolder;

return {
init: function(){
errorHolder = f.find('#alert')[0];

f.subscribe({
'input-error' : this.showError
});
},

destroy: function(){
errorHolder = null;
},

showError: function( msg ){
f.setHTML(errorHolder, msg.value);
}
}
});

app.core.define("#todo-list", function (f) {
var todo, todoItems, renderedItems;
Expand All @@ -111,21 +133,30 @@ app.core.define("#todo-list", function (f) {
addItem : function ( todoItem ) {
var entry;

entry = f.createElement("li", {
id : "todo-" + todoItem.id,
children : [
f.createElement("span", { 'class' : 'item_name',text : todoItem.value })
],
'class' : 'todo_entry'
});
if(todoItem.value !== ""){


todo.appendChild(entry);

entry = f.find('#todo-' + todoItem.id)[0];
f.css(entry, {'color': f.getRandomColor(), 'background': f.getRandomColor()});
f.animate(entry, {'line-height':'50'}, 500);
todoItems[todoItem.id] = 1;
entry = f.createElement("li", {
id : "todo-" + todoItem.id,
children : [
f.createElement("span", { 'class' : 'item_name',text : todoItem.value })
],
'class' : 'todo_entry'
});


todo.appendChild(entry);

entry = f.find('#todo-' + todoItem.id)[0];
f.css(entry, {'color': f.getRandomColor(), 'background': f.getRandomColor()});
f.animate(entry, {'line-height':'50'}, 500);
todoItems[todoItem.id] = 1;

}else{
f.publish({
type : 'input-error',
data : {value: 'Please input a valid todo entry'}
});
}

}
};
Expand Down

0 comments on commit 644c337

Please sign in to comment.