Validate candidate name

This commit is contained in:
ricola 2025-12-04 02:23:04 +01:00
parent f8b5f80823
commit b2e76f4363
3 changed files with 49 additions and 14 deletions

View file

@ -40,14 +40,21 @@
<% if @vote.candidates.empty? %>
<p class="alert alert-primary mb-4"><%= _("This vote has no candidates yet. Add a first candidate.") %></p>
<% end %>
<% if @errors %>
<% @errors.each do |error| %>
<% if error.attribute == :name and error.type == :blank %>
<p class="alert alert-warning mb-4"><%= _("Enter a name.") %></p>
<% end %>
<% end %>
<% end %>
<form action="/votes/<%= @vote.secure_id %>/candidates" method="post">
<div class="mb-3">
<label for="name" class="form-label"><%= _("Name") %></label>
<input type="text" name="name" class="form-control">
<input type="text" name="name" value="<%= params[:name] %>" class="form-control">
</div>
<div class="mb-3">
<label for="description" class="form-label"><%= _("Description") %></label>
<textarea type="text" name="description" class="form-control"></textarea>
<textarea type="text" name="description" class="form-control"><%= params[:description] %></textarea>
</div>
<% if @vote.candidates.length < 2 %>
<button type="submit" class="btn btn-primary"><%= _("Add candidate") %></button>