Use number fields to enter number of votes
This way the fields are easier to use, and we can get rid of the placeholders. Note we're simplifying the `answer_result_value` in order to make it easier to return `0` instead of `nil` when the field is empty. Also note there's a small change of behavior here; previously, these fields were empty by default, and now their value is `0` by default, so blindly clicking the "Save" button would send `0` instead of an empty value. I don't think it's a big deal, though, but we need to keep that in mind.
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
<% question.question_options.each_with_index do |option, i| %>
|
||||
<div class="small-12 medium-6 large-3 column end">
|
||||
<%= label_tag "questions_#{question.id}_#{i}", option.title %>
|
||||
<%= text_field_tag "questions[#{question.id}][#{i}]", answer_result_value(question.id, i), placeholder: "0" %>
|
||||
<%= number_field_tag "questions[#{question.id}][#{i}]", answer_result_value(question.id, i), min: 0 %>
|
||||
</div>
|
||||
<% end %>
|
||||
</fieldset>
|
||||
@@ -24,17 +24,17 @@
|
||||
<div class="row">
|
||||
<div class="small-12 medium-6 large-3 column">
|
||||
<%= label_tag :whites, t("officing.results.new.ballots_white") %>
|
||||
<%= text_field_tag :whites, params[:whites].presence, placeholder: "0" %>
|
||||
<%= number_field_tag :whites, params[:whites].to_i, min: 0 %>
|
||||
</div>
|
||||
|
||||
<div class="small-12 medium-6 large-3 column end">
|
||||
<%= label_tag :nulls, t("officing.results.new.ballots_null") %>
|
||||
<%= text_field_tag :nulls, params[:nulls].presence, placeholder: "0" %>
|
||||
<%= number_field_tag :nulls, params[:nulls].to_i, min: 0 %>
|
||||
</div>
|
||||
|
||||
<div class="small-12 medium-6 large-3 column end">
|
||||
<%= label_tag :total, t("officing.results.new.ballots_total") %>
|
||||
<%= text_field_tag :total, params[:total].presence, placeholder: "0" %>
|
||||
<%= number_field_tag :total, params[:total].to_i, min: 0 %>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
|
||||
@@ -10,10 +10,6 @@ class Officing::Results::FormComponent < ApplicationComponent
|
||||
private
|
||||
|
||||
def answer_result_value(question_id, option_index)
|
||||
return nil if params.blank?
|
||||
return nil if params[:questions].blank?
|
||||
return nil if params[:questions][question_id.to_s].blank?
|
||||
|
||||
params[:questions][question_id.to_s][option_index.to_s]
|
||||
params.dig(:questions, question_id.to_s, option_index.to_s).to_i
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user