Skip to content
Open
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
13 changes: 11 additions & 2 deletions templates/components/itilobject/timeline/form_validation.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@
// set validator type
$("#dropdown__validatortype_{{ rand }}").trigger('setValue', data.validatortype);
// Approver is a group or multiple users of a group
if (data.groups_id !== undefined && data.groups_id !== null) {
waitForElement("#dropdown_groups_id{{ rand }}").then((elm) => {
// set groups_id
Expand All @@ -360,11 +361,19 @@
waitForElement("#dropdown_items_id_target{{ rand }}").then((elm) => {
// set items_id_target
$("#dropdown_items_id_target{{ rand }}").ready(function() {
$("#dropdown_items_id_target{{ rand }}").trigger('setValue', data.items_id_target);
if (Array.isArray(data.items_id_target)) {
$("#dropdown_items_id_target{{ rand }}").val(data.items_id_target);
$("#dropdown_items_id_target{{ rand }}").trigger('change');
} else {
$("#dropdown_items_id_target{{ rand }}").trigger('setValue', data.items_id_target);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think setValue was added as an event for another reason besides just grouping .val() and .trigger('change') into a single call.

A better solution is fixing the handling of the event listener(s) for setValue in common.js or changing each call to trigger the event so the array is packed within another array or an object.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that making setValue able to handle single values and also arrays is a good point.
Function able to do lots of things results in more complex code, hard to maintain. Maybe implementing a new method for array is a solution (it depends if there is more than a couple of candidates to use it).
I think this core change can be postponed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't a separate thing. It is setting a value and triggering the change event regardless of if it is one selection or multiple. The only part of setValue handling that seems different to me is one listener that triggers an AJAX call. I haven't looked too much at it to know what it is doing exactly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I agree on the general principal that fixing/improving the js core is the best general bet, I think making a change that has possible impact on all glpi is not what we should target now. I guess you should open another issue for that point, for later.

}
});
});
});
} else if (data.items_id_target !== undefined) {
}
// Approver is a single user
else if (data.items_id_target !== undefined)
{
new Promise((resolve) => {
// if dropdown_items_id_target exists, wait for it to be removed
// is required because the dropdown is removed and recreated when the setValue is triggered
Expand Down