Skip to content

Commit bc3d891

Browse files
authored
Check package only benefits as well (#1670)
A package only benefit's checkbox is rendered in the HTML with the disabled attribute. Because of that, the click event wasn't being triggered by the browser. This fix turn off and on this attribute so the click event can happen.
1 parent e4a3d88 commit bc3d891

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

static/js/sponsors/applicationForm.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@ $(document).ready(function(){
1717

1818
checkboxesContainer.find(':checkbox').each(function(){
1919
$(this).prop('checked', false);
20+
let packageOnlyBenefit = $(this).attr("package_only");
21+
if (packageOnlyBenefit) $(this).attr("disabled", true);
2022
});
2123

2224
let packageInfo = $("#package_benefits_" + package);
2325
packageInfo.children().each(function(){
2426
let benefit = $(this).html()
25-
checkboxesContainer.find(`[value=${benefit}]`).trigger("click");
27+
let benefitInput = checkboxesContainer.find(`[value=${benefit}]`);
28+
let packageOnlyBenefit = benefitInput.attr("package_only");
29+
benefitInput.removeAttr("disabled");
30+
benefitInput.trigger("click");
2631
});
2732

2833
let url = $("#cost_container").attr("calculate_cost_url");
@@ -38,7 +43,12 @@ $(document).ready(function(){
3843
if (costLabel.html() != "Updating cost...") costLabel.html("Submit your application and we'll get in touch...");
3944

4045
let active = checkboxesContainer.find(`[value=${benefit}]`).prop("checked");
41-
if (!active) return;
46+
if (!active) {
47+
let packageOnlyBenefit = $(this).attr("package_only");
48+
if (packageOnlyBenefit) $(this).attr("disabled", true);
49+
return;
50+
}
51+
4252

4353
$(`#conflicts_with_${benefit}`).children().each(function(){
4454
let conflictId = $(this).html();

templates/sponsors/sponsorship_benefits_form.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ <h3 class="title">{{ field.label }}</h3>
4848
{% for benefit in field.field.queryset %}
4949
<li class="{% cycle '' 'highlight' %}">
5050
<label for="id_{{field.name}}_{{ forloop.counter0 }}" title="{{ benefit.unavailability_message }}">
51-
<input id="id_{{field.name}}_{{ forloop.counter0 }}" name="{{ field.name }}" type="checkbox" value="{{ benefit.id }}" {% if benefit.unavailability_message %}disabled{% endif %} {% if benefit.id in field.initial %}checked{% endif %}>
51+
<input id="id_{{field.name}}_{{ forloop.counter0 }}" name="{{ field.name }}" type="checkbox" value="{{ benefit.id }}" {% if benefit.unavailability_message %}disabled{% endif %} {% if benefit.id in field.initial %}checked{% endif %} {% if benefit.package_only %}package_only='true'{% endif %}>
5252
{{ benefit.name }}
5353
{% if benefit.new %}<span class="fa fa-asterisk"></span>{% endif %}
5454
{% if benefit.package_only %}<i class="fa fa-cubes"></i>{% endif %}

0 commit comments

Comments
 (0)