Project

General

Profile

[view-customize plugin] I want to control the items displayed in the pull-down menu

Added by rito matsu 3 months ago

I want to use the redmine-view-customize plugin to display pull-down custom fields.
The following code works in my local environment, but did not work when written to Redmine.
If there is an error in the code or the use of the plugin, please let me know.
I am having trouble understanding how to check the logs.

path-pattern

/issues/[0-9]+

project-pattern

/sandbox


$(document).ready(function () {
    var parentField = 'issue_custom_field_values_1';
    var childField = 'issue_custom_field_values_2';

    var narrowChildField = function() {
          var optionList = [
            {parent: 36, children: [57, 59, 60, 20]},
            {parent: 42, children: [59, 61]},
            {parent: 43, children: [60]},
            {parent: 0, children: [57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 20]}
        ];

          var parentId = parseInt($('#' + parentField + ' > option:selected').data('select2-id'), 10);
          if (isNaN(parentId)) {
            console.error("Invalid Children ID.");
            return;
          }

          var selectedOption = optionList.find(o => o.parent === parentId);
        var childIds = selectedOption ? selectedOption.children : [];

          $('#' + childField + ' > option').each(function() {
            var childId = parseInt($(this).data('select2-id'), 10);
            if (isNaN(childId)) {
              console.error("Invalid child ID for option:", $(this).text());
              return;
            }

            if (childIds.includes(childId)) {
                  $(this).show();
            } else {
                  $(this).hide();
            }
          });
    };
    narrowChildField();

    $('#all_attributes').change(function(e) {
        if (e.target.id === parentField) {
            narrowChildField();
          }
    });

    if (typeof replaceIssueFormWith === 'function') {
        var _replaceIssueFormWith = replaceIssueFormWith;
        replaceIssueFormWith = function(html){
            _replaceIssueFormWith(html);
            narrowChildField();
          };
    }
});

Thank you in advance for your help.


Replies (2)

RE: [view-customize plugin] I want to control the items displayed in the pull-down menu - Added by rito matsu 3 months ago

Thank you for checking.
By writing the above code, I was able to control the custom fields in the pulldown. However, sometimes when I press an option, the hidden item appears. I would like to know how to deal with this.

    (1-2/2)