Skip to content

Commit

Permalink
Added form partial to the mongo example
Browse files Browse the repository at this point in the history
  • Loading branch information
Techwraith committed Mar 13, 2012
1 parent f01c2d5 commit c3b5119
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions examples/todo_app_mongo/app/views/todos/_form.html.ejs
@@ -0,0 +1,46 @@
<%
var isUpdate = params.action == 'edit'
, formTitle = isUpdate ? 'Update this To Do Item' : 'Create a new To Do Item'
, action = isUpdate ? '/todos/' + todo.id + '?_method=PUT' : '/todos'
, deleteAction = isUpdate ? '/todos/' + todo.id + '?_method=DELETE' : ''
, btnText = isUpdate ? 'Update' : 'Add'
, doneStatus = isUpdate ? 'checked' : ''
, titleValue = isUpdate ? todo.title : ''
, errors = params.errors;
%>
<form id="todo-form" class="form-horizontal" action="<%= action %>" method="POST">
<fieldset>
<legend><%= formTitle %></legend>
<div class="control-group">
<label for="title" class="control-label">Title</label>
<div class="controls">
<input type="text" class="span6" placeholder="enter title" name="title" value='<%= titleValue %>'/>
<% if (errors) { %>
<p>
<% for (var p in errors) { %>
<div><%= errors[p]; %></div>
<% } %>
</p>
<% } %>
</div>
</div>
<% if (isUpdate) { %>
<div class="control-group">
<label for="status">Status</label>
<div class="controls">
<select name="status">
<option>open</option>
<option>done</option>
</select>
</div>
</div>
<% } %>
<div class="form-actions">
<input type="submit" class="btn btn-primary" value="<%= btnText %>"/>
<% if (isUpdate) { %>
<button type="submit" formaction="<%= deleteAction %>" formmethod="POST" class="btn btn-danger">Remove</button>
<% } %>
</div>
</fieldset>
</form>

0 comments on commit c3b5119

Please sign in to comment.