Skip to content

Commit

Permalink
Prevent negative time entry
Browse files Browse the repository at this point in the history
  • Loading branch information
karmenlu committed Mar 1, 2019
1 parent 09d9661 commit c6bd2a4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion tasks1/lib/tasks1_web/controllers/task_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ defmodule Tasks1Web.TaskController do
task = Tasks.get_task!(id)

task_params = Map.put(task_params, "doer_id", _parse_doer(Map.get(task_params, "doer_id")))
task_params = Map.put(task_params, "timeSpent", closestFifteen(elem(Integer.parse(Map.get(task_params, "timeSpent")), 0)))
if Map.get(task_params, "timeSpent", nil) != nil do
task_params = Map.put(task_params, "timeSpent", closestFifteen(elem(Integer.parse(Map.get(task_params, "timeSpent")), 0)))
else
end
case Tasks.update_task(task, task_params) do
{:ok, task} ->
conn
Expand Down
2 changes: 1 addition & 1 deletion tasks1/lib/tasks1_web/templates/task/form.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

<div class="form-group">
<%= label f, :timeSpent %>
<%= number_input f, :timeSpent, step: 15 %>
<%= number_input f, :timeSpent, step: 15, min: 0 %>
<%= error_tag f, :timeSpent %>
</div>
<% end %>
Expand Down

0 comments on commit c6bd2a4

Please sign in to comment.