diff --git a/app/javascript/controllers/evaluation_form_controller.js b/app/javascript/controllers/evaluation_form_controller.js index 1038dce9..90605314 100644 --- a/app/javascript/controllers/evaluation_form_controller.js +++ b/app/javascript/controllers/evaluation_form_controller.js @@ -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") diff --git a/app/views/evaluation_forms/_evaluation_criterion_fields.html.erb b/app/views/evaluation_forms/_evaluation_criterion_fields.html.erb index 793bf1ff..5d202fdc 100644 --- a/app/views/evaluation_forms/_evaluation_criterion_fields.html.erb +++ b/app/views/evaluation_forms/_evaluation_criterion_fields.html.erb @@ -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, diff --git a/app/views/evaluation_forms/_form.html.erb b/app/views/evaluation_forms/_form.html.erb index c5ec96b7..cbc78bcc 100644 --- a/app/views/evaluation_forms/_form.html.erb +++ b/app/views/evaluation_forms/_form.html.erb @@ -81,11 +81,29 @@
- <%= 'disabled' unless !disabled %>> + + <%= 'disabled' if disabled %> + >
- <%= 'disabled' unless !disabled %>> + + <%= 'disabled' if disabled %> + >