N°3750 Add data-input-id to field container

This will allow easiest DOM manipulation in BeHat tests
This commit is contained in:
Pierre Goiffon
2021-02-24 17:13:47 +01:00
parent 8295920c3c
commit c8911f1fa9
4 changed files with 29 additions and 17 deletions

View File

@@ -906,6 +906,7 @@ EOF
$val = array(
'label' => '<span '.$sDescriptionHTMLTag.' >'.$oAttDef->GetLabel().'</span>',
'value' => $sHTMLValue,
'inputId' => $sInputId,
'comments' => $sComments,
'infos' => $sInfos,
);

View File

@@ -337,7 +337,12 @@ class Field extends UIContentBlock
public function SetValueId(?string $sValueId)
{
$this->sValueId = $sValueId;
return $this;
}
public function SetInputId(string $sInputId)
{
$this->AddDataAttribute('input-id', $sInputId);
}
}

View File

@@ -31,6 +31,7 @@ class FieldUIBlockFactory extends AbstractUIBlockFactory
'attlabel' => 'SetAttLabel',
'value_raw' => 'SetValueRaw',
'comments' => 'SetComments',
'inputId' => 'SetInputId',
];
foreach ($aParamsMapping as $sParamKey => $sFieldMethod) {
self::UpdateFieldFromParams($oField, $sFieldMethod, $aParams, $sParamKey);

View File

@@ -7,24 +7,29 @@
data-attribute-code="{{ oUIBlock.GetAttCode() }}"
data-attribute-type="{{ oUIBlock.GetAttType() }}"
data-attribute-label="{{ oUIBlock.GetAttLabel() }}"
{# Note: This might not the best way to this, we might rather have some properties for this flags in te Field class. #}
{# For the moment this just aims at restoring the metadata introduced in iTop 2.7. Refactoring the Field class with specialization for each type must be designed by all the team #}
{# as we might want to re-use / adapt the Field classes introduced with the end-user portal #}
data-attribute-flag-hidden="{{ oUIBlock.IsHidden()|var_export }}"
data-attribute-flag-read-only="{{ oUIBlock.IsReadOnly()|var_export }}"
data-attribute-flag-mandatory="{{ oUIBlock.IsMandatory()|var_export }}"
data-attribute-flag-must-change="{{ oUIBlock.IsMustChange()|var_export }}"
data-attribute-flag-must-prompt="{{ oUIBlock.IsMustPrompt()|var_export }}"
data-attribute-flag-slave="{{ oUIBlock.IsSlave()|var_export }}"
data-value-raw="{{ aParams.value_raw }}"
{# Note: This might not the best way to this, we might rather have some properties for this flags in te Field class. #}
{# For the moment this just aims at restoring the metadata introduced in iTop 2.7. Refactoring the Field class with specialization for each type must be designed by all the team #}
{# as we might want to re-use / adapt the Field classes introduced with the end-user portal #}
data-attribute-flag-hidden="{{ oUIBlock.IsHidden()|var_export }}"
data-attribute-flag-read-only="{{ oUIBlock.IsReadOnly()|var_export }}"
data-attribute-flag-mandatory="{{ oUIBlock.IsMandatory()|var_export }}"
data-attribute-flag-must-change="{{ oUIBlock.IsMustChange()|var_export }}"
data-attribute-flag-must-prompt="{{ oUIBlock.IsMustPrompt()|var_export }}"
data-attribute-flag-slave="{{ oUIBlock.IsSlave()|var_export }}"
data-value-raw="{{ aParams.value_raw }}"
{% if oUIBlock.GetDataAttributes() %}
{% for sName, sValue in oUIBlock.GetDataAttributes() %}
data-{{ sName }}="{{ sValue }}"
{% endfor %}
{% endif %}
>
<div class="ibo-field--label">{{ oUIBlock.GetLabel()|raw }}</div>
<div class="ibo-field--value" {% if oUIBlock.GetValueId() %}id="{{ oUIBlock.GetValueId() }}"{% endif %}>
{% for oSubBlock in oUIBlock.GetSubBlocks() %}
{{ render_block(oSubBlock, {aPage: aPage}) }}
{% endfor %}
</div>
{% if oUIBlock.GetComments() %}
<div class="ibo-field--label">{{ oUIBlock.GetLabel()|raw }}</div>
<div class="ibo-field--value" {% if oUIBlock.GetValueId() %}id="{{ oUIBlock.GetValueId() }}"{% endif %}>
{% for oSubBlock in oUIBlock.GetSubBlocks() %}
{{ render_block(oSubBlock, {aPage: aPage}) }}
{% endfor %}
</div>
{% if oUIBlock.GetComments() %}
<div class="ibo-field--comments">{{ oUIBlock.GetComments()|raw }}</div>
{% endif %}
</div>