TEXHIK
TEXHIK

Reputation: 1398

How to hide empty fields with custom control?

Fields, that have not any configured control:

<field-visibility>
    <show id="foo:bar"/>
</field-visibility>
<appearance>
    <field id="foo:bar" read-only="true" />
</appearance>

is only displayed when they have value, even in edit-mode, as of they are read-only.

However, when I tried to add a custom control to the field, it is always displayed and readonly doesn't work:

<field-visibility>
    <show id="foo:bar"/>
</field-visibility>
<appearance>
    <field id="foo:bar" read-only="true">
        <control template="/com/myCompany/myTemplate">
            <control-param name="myParam">value</control-param>
        </control>
    </field>
</appearance>

How to configure the field to be only displayed if thre is a value in it?

Upvotes: 0

Views: 502

Answers (1)

Tahir Malik
Tahir Malik

Reputation: 6643

take a look at the hidden.ftl as an appearance template: org\alfresco\components\form\controls\hidden.ftl

And the textfield: org\alfresco\components\form\controls\textfield.ftl

In the textfield.ftl you'll see the following:

<span class="viewmode-label">${field.label?html}:</span>
......
<#if fieldValue == "">${msg("form.control.novalue")}<#else>${fieldValue}</#if></span>

On the label side surround it with an <#if fieldValue == ""> and remove the the following code resided in the if fieldValue ${msg("form.control.novalue")}

Upvotes: 1

Related Questions