Skip to content

Commit

Permalink
fixes #275
Browse files Browse the repository at this point in the history
  • Loading branch information
stepchud committed Nov 14, 2024
1 parent ac68052 commit f404e36
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
10 changes: 10 additions & 0 deletions app/javascript/controllers/evaluation_form_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ export default class extends Controller {
}
}

updateMaxPoints(e) {
const form = e.target.closest('form[data-controller="evaluation-form"]');
const pointsWeights = form.querySelectorAll(".points-or-weight");
if (e.target.id == 'weighted_scale') {
pointsWeights.forEach((input) => input.max = "100")
} else {
pointsWeights.forEach((input) => input.max = "9999")
}
}

validatePresence(e) {
if (!e.target.value) {
e.target.classList.add("border-secondary")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@
<%= f.number_field :points_or_weight,
id: criteria_field_id(f, "points_or_weight", is_template),
name: criteria_field_name(f, "points_or_weight", is_template),
class: "usa-input flex-1 margin-top-0 margin-right-2 font-sans-lg",
class: "points-or-weight usa-input flex-1 margin-top-0 margin-right-2 font-sans-lg",
min: 1,
max: f.object.evaluation_form&.weighted_scoring? ? 100 : 9999,
step: 1,
placeholder: "Add criteria points/weight here",
required: true,
Expand Down
22 changes: 20 additions & 2 deletions app/views/evaluation_forms/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,29 @@
</legend>
<div class="display-flex flex-row">
<div class="usa-radio margin-right-205">
<input class="usa-radio__input" id="point_scale" type="radio" name="evaluation_form[weighted_scoring]" value="false" <%= 'checked' unless evaluation_form.weighted_scoring %> <%= 'disabled' unless !disabled %>>
<input
class="usa-radio__input"
id="point_scale"
type="radio"
name="evaluation_form[weighted_scoring]"
value="false"
data-action="input->evaluation-form#updateMaxPoints"
<%= 'checked' unless evaluation_form.weighted_scoring %>
<%= 'disabled' if disabled %>
>
<label class="usa-radio__label font-sans-xs" for="point_scale">Point Scale</label>
</div>
<div class="usa-radio">
<input class="usa-radio__input" id="weighted_scale" type="radio" name="evaluation_form[weighted_scoring]" value="true" <%= 'checked' if evaluation_form.weighted_scoring %> <%= 'disabled' unless !disabled %>>
<input
class="usa-radio__input"
id="weighted_scale"
type="radio"
name="evaluation_form[weighted_scoring]"
value="true"
data-action="input->evaluation-form#updateMaxPoints"
<%= 'checked' if evaluation_form.weighted_scoring %>
<%= 'disabled' if disabled %>
>
<label class="usa-radio__label font-sans-xs" for="weighted_scale">Weighted Scale (%)</label>
</div>
</div>
Expand Down

0 comments on commit f404e36

Please sign in to comment.