Skip to content

fix(forms): Ensure consistent dropdown labels for Item questions in f…#23507

Open
ccailly wants to merge 2 commits intoglpi-project:11.0/bugfixesfrom
ccailly:fix/form-item-question-type-displaywith-consistent
Open

fix(forms): Ensure consistent dropdown labels for Item questions in f…#23507
ccailly wants to merge 2 commits intoglpi-project:11.0/bugfixesfrom
ccailly:fix/form-item-question-type-displaywith-consistent

Conversation

@ccailly
Copy link
Member

@ccailly ccailly commented Mar 17, 2026

Checklist before requesting a review

Please delete options that are not relevant.

  • I have read the CONTRIBUTING document.
  • I have performed a self-review of my code.
  • I have added tests that prove my fix is effective or that my feature works.

Description

Ensure that the labels in the dropdown menus for “Item” questions remain the same regardless of whether they have been saved or not.
Currently, we have more information available when selecting an item before saving and reloading the page.
The display is now consistent between the form editor and the end-user interface.

Screenshots (if appropriate):

Before (for saved question)

image

After (for saved question)

image

Copy link
Contributor

@AdrienClairembault AdrienClairembault left a comment

Choose a reason for hiding this comment

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

CI is red.

Copy link
Contributor

@AdrienClairembault AdrienClairembault left a comment

Choose a reason for hiding this comment

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

The AJAX endpoint dropdownAllItems.php:60 (used when dynamically switching itemtype for unsaved questions) hardcodes:

  • ITIL types → ['id']
  • Everything else → ['otherserial', 'serial']

The new getDisplayWith() method computes a different set:

  • ITIL types → ['id']
  • Asset types → ['otherserial', 'serial', 'users_id']
  • Non-asset, non-ITIL → []

This means saved questions with Computer type will show users_id in the dropdown while unsaved questions (loaded via AJAX) will not. The consistency goal isn't fully achieved for asset types.

Centralizing the logic so both paths call the same computation would be great.

});

// Switch to the new entity and refresh session to ensure the new entity is taken into account in the session
entity.switchToWithoutRecursion(entity_id);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
entity.switchToWithoutRecursion(entity_id);
await entity.switchToWithoutRecursion(entity_id);


test.afterEach(async ({ entity, api }) => {
// Reset entity to default one to avoid issues with other tests in the same worker
entity.resetToDefaultWorkerEntity();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
entity.resetToDefaultWorkerEntity();
await entity.resetToDefaultWorkerEntity();

const persisted_question = form.getLastQuestion();
await persisted_question.click({ position: { x: 0, y: 0 } });

form.getDropdownByLabel('Select an item', persisted_question).click();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
form.getDropdownByLabel('Select an item', persisted_question).click();
await form.getDropdownByLabel('Select an item', persisted_question).click();

await form.setSubQuestionType(new_question, 'GLPI Objects');
await form.setItemTypeForItemQuestion(new_question, 'Computers');

form.getDropdownByLabel('Select an item', new_question).click();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
form.getDropdownByLabel('Select an item', new_question).click();
await form.getDropdownByLabel('Select an item', new_question).click();

* @param string|null $itemtype The itemtype to compute displaywith for.
* @return array<string>
*/
public function getDisplayWith(?string $itemtype): array
Copy link
Contributor

Choose a reason for hiding this comment

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

Method is public but is only used internally, is it normal?

Comment on lines +388 to +390
if ($item->isField('serial')) {
$displaywith[] = 'serial';
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I see you changed this for consistency with the ajax dropdown endpoint but maybe this order should be the one being kept? I think the main serial number is more important and should be displayed first.

Or we keep it like that to prevent changes on a bugfix and we use serial -> serialnumber everywhere on main.

@cedric-anne cedric-anne added this to the 11.0.7 milestone Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants