Menu

Dynamic display by Twig

Kevin
2024-01-18
2024-01-19
  • Kevin

    Kevin - 2024-01-18

    Hello to all,

    I try to show/hide some field depending on service selected.
    I tried those codes :

    <div class="col-sm-6">
        {% if service_id != 18 %}
            <div class="form_field" data-field-id="product_impacted" data-field-flags="mandatory"></div>
        {% else %}
            <div class="form_field" data-field-id="uct_product_impacted" data-field-flags="mandatory"></div>
            {% endif %}
    </div>
    

    and

    <div class="col-sm-6">
        {% if service_id != "Unified Connect" %}
            <div class="form_field" data-field-id="product_impacted" data-field-flags="mandatory"></div>
        {% else %}
            <div class="form_field" data-field-id="uct_product_impacted" data-field-flags="mandatory"></div>
        {% endif %}
    </div>
    

    But the 1st field is always displayed...

    Could it be possible to check another field value in the twig ?

    Kind regards,

     
  • Jeffrey Bostoen

    Jeffrey Bostoen - 2024-01-18

    service_id would probably indeed be a number, but I'm not sure you can directly access the attribute value that way?

     
  • Kevin

    Kevin - 2024-01-18

    Thanks for your answer.
    Yes, that's why I tried "if service_id != 18" but the if is always "true"...
    I will wait if someone else know if it is possible or not :)

     
  • Kevin

    Kevin - 2024-01-18

    I bypassed the problem :p
    I created a new class Product and the field in ticket is a SELECT query based on the Service ID :)

     
  • Guillaume Lajarige

    Hello Kevin, if you want to achieve this you shouldn't do it in the TWIG directly, but in the object GetInitialAttributeFlags() method.

    The idea is to:
    - In the datamodel define the dependancy between 2 fields
    - In the GetInitialAttribuetFlags() method, set the flag to hidden depending on the value of the other attribute

    Hope thie helps,
    Guillaume

     
    👍
    1

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.