Skip to content

Commit

Permalink
VACMS-16574: Remove tag topic restrictions. (#16854)
Browse files Browse the repository at this point in the history
* VACMS-16574: Remove function to enforce max number of tags.

* VACMS-16574: Update help text.

* VACMS-16574: Remove portions of test related to restricting the tags.

* VACMS-16574: Allow for unlimited topics.

* VACMS-16574: Remove validation for 4 or more topic/audience tags.

---------

Co-authored-by: Steve Wirt <[email protected]>
  • Loading branch information
Becapa and swirtSJW authored Jan 16, 2024
1 parent 51a8473 commit ffbefda
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ default_value:
default_value_callback: ''
settings:
markup:
value: "<p>Select tags for your article (minimum of 1, max of 4).<br />\r\nTags allow users to see more articles for that tag.<br />\r\nSelect one to four tags that are most relevant for this article.<br />\r\nYou can select a combination of Topics and Audiences.</p>\r\n"
value: "<p>Select tags for your article.<br />\r\nTags allow users to see more articles for that tag.<br />\r\nYou can select a combination of Topics and Audiences.</p>\r\n"
format: rich_text
field_type: markup
2 changes: 1 addition & 1 deletion config/sync/field.storage.paragraph.field_topics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ settings:
target_type: taxonomy_term
module: core
locked: false
cardinality: 4
cardinality: -1
translatable: true
indexes: { }
persist_with_no_fields: false
Expand Down
78 changes: 0 additions & 78 deletions docroot/modules/custom/va_gov_backend/js/audience_topics.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,80 +3,6 @@
*/

(($, Drupal) => {
/**
* Ensure that a maximum of 4 tags + audiences may be selected.
*/
function enforceMaximumNumberOfTags() {
// Get the total number of tags selected in the Topics fields.
let total = $('div[id^="edit-field-tags-0-subform-field-topics"]').find(
"input:checked"
).length;

// Prevent showing the Beneficiaries field if we already have 4 topic tags.
if (total >= 4) {
$(
'select[id^="edit-field-tags-0-subform-field-audience-selection"]'
).attr("disabled", true);
$("div.form-item-field-tags-0-subform-field-audience-selection").addClass(
"form-disabled"
);

$(
'div[id^="edit-field-tags-0-subform-field-audience-beneficiares-none"]'
).attr("checked", true);
$(
'div[id^="edit-field-tags-0-subform-field-non-beneficiares-none"]'
).attr("checked", true);

$(
'div[id^="edit-field-tags-0-subform-field-non-beneficiares-wrapper"]'
).hide();
$(
'div[id^="edit-field-tags-0-subform-field-audience-beneficiares-wrapper"]'
).hide();
$('select[id^="edit-field-tags-0-subform-field-audience-selection"]').val(
"_none"
);
} else {
$(
'select[id^="edit-field-tags-0-subform-field-audience-selection"]'
).attr("disabled", false);
$(
"div.form-item-field-tags-0-subform-field-audience-selection"
).removeClass("form-disabled");
}
// Find out if there is a Beneficiary/Non-beneficiary term selected and increase the total if so.
let audienceSelected = $(
'div[id^="edit-field-tags-0-subform-field-audience-beneficiares-wrapper"]'
).find(
'input:not([id^="edit-field-tags-0-subform-field-audience-beneficiares-none"]):checked'
).length;
if (
$(
'select[id^="edit-field-tags-0-subform-field-audience-selection"]'
).val() === "non-beneficiaries"
) {
audienceSelected = $(
'div[id^="edit-field-tags-0-subform-field-non-beneficiares-wrapper"]'
).find(
'input:not([id^="edit-field-tags-0-subform-field-non-beneficiares-none"]):checked'
).length;
}

total += audienceSelected;

if (total >= 4) {
// If a total of four or more tags have been selected, prevent the user from selecting more.
$('div[id^="edit-field-tags-0-subform-field-topics"]')
.find("input[type=checkbox]:not(:checked)")
.attr("disabled", true);
} else {
// Otherwise, ensure that more tags may be selected.
$('div[id^="edit-field-tags-0-subform-field-topics"]')
.find("input[type=checkbox]")
.attr("disabled", false);
}
}

Drupal.behaviors.vaGovAudienceTopics = {
attach() {
Expand Down Expand Up @@ -123,8 +49,6 @@
.parent()
.hide();

// Enforce tag selection rules.
enforceMaximumNumberOfTags();
// React when the tags fieldset changes.
$("fieldset#edit-group-tags").change(() => {
const selection = $(
Expand Down Expand Up @@ -174,8 +98,6 @@
true
);
}
// Enforce tag selection rules.
enforceMaximumNumberOfTags();
});
},
};
Expand Down
43 changes: 0 additions & 43 deletions docroot/modules/custom/va_gov_backend/js/audience_topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,7 @@
* https://www.drupal.org/node/2815083
* @preserve
**/

(function ($, Drupal) {
function enforceMaximumNumberOfTags() {
var total = $('div[id^="edit-field-tags-0-subform-field-topics"]').find("input:checked").length;

if (total >= 4) {
$('select[id^="edit-field-tags-0-subform-field-audience-selection"]').attr("disabled", true);
$("div.form-item-field-tags-0-subform-field-audience-selection").addClass("form-disabled");

$('div[id^="edit-field-tags-0-subform-field-audience-beneficiares-none"]').attr("checked", true);
$('div[id^="edit-field-tags-0-subform-field-non-beneficiares-none"]').attr("checked", true);

$('div[id^="edit-field-tags-0-subform-field-non-beneficiares-wrapper"]').hide();
$('div[id^="edit-field-tags-0-subform-field-audience-beneficiares-wrapper"]').hide();
$('select[id^="edit-field-tags-0-subform-field-audience-selection"]').val("_none");
} else {
$('select[id^="edit-field-tags-0-subform-field-audience-selection"]').attr("disabled", false);
$("div.form-item-field-tags-0-subform-field-audience-selection").removeClass("form-disabled");
}

var audienceSelected = $('div[id^="edit-field-tags-0-subform-field-audience-beneficiares-wrapper"]').find('input:not([id^="edit-field-tags-0-subform-field-audience-beneficiares-none"]):checked').length;
if ($('select[id^="edit-field-tags-0-subform-field-audience-selection"]').val() === "non-beneficiaries") {
audienceSelected = $('div[id^="edit-field-tags-0-subform-field-non-beneficiares-wrapper"]').find('input:not([id^="edit-field-tags-0-subform-field-non-beneficiares-none"]):checked').length;
}

total += audienceSelected;

if (total >= 4) {
$('div[id^="edit-field-tags-0-subform-field-topics"]').find("input[type=checkbox]:not(:checked)").attr("disabled", true);
} else {
$('div[id^="edit-field-tags-0-subform-field-topics"]').find("input[type=checkbox]").attr("disabled", false);
}
}

Drupal.behaviors.vaGovAudienceTopics = {
attach: function attach() {
if ($('div[id^="edit-field-tags-0-subform-field-non-beneficiares-wrapper"]').find('input:not([id^="edit-field-tags-0-subform-field-non-beneficiares-none"]):checked').length) {
Expand All @@ -49,36 +16,26 @@
$('div[id^="edit-field-tags-0-subform-field-audience-beneficiares-wrapper"]').show();
$('div[id^="edit-field-tags-0-subform-field-non-beneficiares-wrapper"]').hide();
}

$("#edit-group-tags > legend").addClass("form-required");

$('input[id^="edit-field-tags-0-subform-field-audience-beneficiares-none"]').parent().hide();
$('input[id^="edit-field-tags-0-subform-field-non-beneficiares-none"]').parent().hide();

enforceMaximumNumberOfTags();

$("fieldset#edit-group-tags").change(function () {
var selection = $('select[id^="edit-field-tags-0-subform-field-audience-selection"]').val();

$('fieldset#edit-group-tags input[type="radio"]').attr("checked", false);
$('div[id^="edit-field-tags-0-subform-field-audience-beneficiares-wrapper"]').hide();
$('div[id^="edit-field-tags-0-subform-field-non-beneficiares-wrapper"]').hide();
if (selection === "beneficiaries") {
$('div[id^="edit-field-tags-0-subform-field-audience-beneficiares-wrapper"]').show();

$("#edit-field-tags-0-subform-field-non-beneficiares-none").attr("checked", true);
}
if (selection === "non-beneficiaries") {
$('div[id^="edit-field-tags-0-subform-field-non-beneficiares-wrapper"]').show();

$("#edit-field-tags-0-subform-field-audience-beneficiares-none").attr("checked", true);
}
if (selection === "_none") {
$("#edit-field-tags-0-subform-field-non-beneficiares-none").attr("checked", true);
$("#edit-field-tags-0-subform-field-audience-beneficiares-none").attr("checked", true);
}

enforceMaximumNumberOfTags();
});
}
};
Expand Down
3 changes: 0 additions & 3 deletions docroot/modules/custom/va_gov_backend/va_gov_backend.module
Original file line number Diff line number Diff line change
Expand Up @@ -786,9 +786,6 @@ function _va_gov_backend_audience_topics_validation(array $form, FormStateInterf
if ($tag_count == 0) {
$form_state->setErrorByName('field_tags][0][subform][field_topics', t('Please select at least one Topic or Audience tag.'));
}
elseif ($tag_count > 4) {
$form_state->setErrorByName('field_tags][0][subform][field_topics', t('No more than 4 Topic/Audience tags may be selected.'));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,3 @@ Feature: Content Type: Resources and Support Detail Page
Given I select option "Non-beneficiaries" from dropdown "Audience"
Then I should not see an element with the selector "#edit-field-tags-0-subform-field-audience-beneficiares-wrapper"
And I should see an element with the selector "#edit-field-tags-0-subform-field-non-beneficiares-wrapper"

Given I check all checkboxes within "#edit-field-tags-0-subform-field-topics--wrapper"
Then an element with the selector "#edit-field-tags-0-subform-field-audience-selection" should be disabled

Given I uncheck the first checkbox within "#edit-field-tags-0-subform-field-topics--wrapper"
Then an element with the selector "#edit-field-tags-0-subform-field-audience-selection" should not be disabled

0 comments on commit ffbefda

Please sign in to comment.