Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[275] limit points and weight field inputs #276

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading