Skip to content

Fixed issue with hiding conditions not hiding containers in simple ticket view #942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

akstis-typer
Copy link

I was trying to solve issue with display conditions when using simple
view in ticket menu

The issue was that when you add a container, field to it, and then
create display condition, the condition will not work as expected in
simple view of ticket creation. The condition will never be satisfied
and your field will always stay visible, no matter what condition you
created

Turned out, GLPI_POST_ITEM HOOK send item parameter without 'type' and
'itilcategory_id', those fields were contained in options parameter.

This is small work around, works fine for my use case
@DaviidMM
Copy link

DaviidMM commented Apr 11, 2025

Just to clarify: in my fresh installation (latest versions of everything), I had to place the code inside the showForTab function below the line:

$display_condition = new PluginFieldsContainerDisplayCondition();

like this:

...
$display_condition = new PluginFieldsContainerDisplayCondition();

// @akstis-typer code starts here ------
if($item->fields['type'] == "")
{
    $item->fields['type'] = $params['options']['type'];
}
if($item->fields['itilcategories_id'] == "")
{
    $item->fields['itilcategories_id'] = $params['options']['itilcategories_id'];
}
// @akstis-typer code ends here ------

if ($display_condition->computeDisplayContainer($item, $c_id)) {
...

Otherwise, it didn’t work properly in my environment

Moved code after new Display Condition
@DaviidMM
Copy link

DaviidMM commented May 5, 2025

I've been testing this code and works correctly except for one more issue: When a custom field is shown and you edit another field (e.g. title), the custom field's alignment breaks again. My solution was to add echo "<div class='offset-md-1 col-md-8 col-xxl-6'>"; into the ajax/container.php file, inside the if ($display_condition->computeDisplayContainer($item, $containers_id)) { condition:

$display_condition = new PluginFieldsContainerDisplayCondition();
    if ($display_condition->computeDisplayContainer($item, $containers_id)) {
        $field_options = [
            'label_class' => 'col-lg-3',
            'input_class' => 'col-lg-9',
        ];
        echo "<div class='offset-md-1 col-md-8 col-xxl-6'>";
        PluginFieldsField::showDomContainer(
            $containers_id,
            $item,
            $type,
            $subtype,
            $field_options
        );
        echo "</div>";
    } else {
        echo '';
    }

After the showDomContainer method i close the created div with echo "</div>";

@stonebuzz
Copy link
Contributor

Hi @akstis-typer

can you rebase ?

@akstis-typer
Copy link
Author

Hi @akstis-typer

can you rebase ?

Hi, you mean I need to add last changes of original repository? Or something else?
I'm not so good at git so I didn't get it :0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hiding fields depending on category does not work
3 participants