Permalink
Browse files

Added form partial to the mongo example

  • Loading branch information...
1 parent f01c2d5 commit c3b5119d9f82e8c28e5ea79eda0616384d49733c Techwraith committed Mar 13, 2012
Showing with 46 additions and 0 deletions.
  1. +46 −0 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.