How do I create a label for a custom Orbeon control

436 Views Asked by At

The label is missing the "for" attribute on my custom control. I was using lhha mode, but have now switched to custom-lhha mode to try to correct the issue.

The code below is doing something very odd. The label element contains two nested spans with the correct label content and the for attribute contains a partial of the correct id.

<xbl:xbl xmlns:xh="http://www.w3.org/1999/xhtml"
     xmlns:xf="http://www.w3.org/2002/xforms"
     xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
     xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
     xmlns:xbl="http://www.w3.org/ns/xbl"
     xmlns:xxbl="http://orbeon.org/oxf/xml/xbl">

<xbl:binding element="fr|image-picker" id="fr-image-picker" xxbl:mode="lhha custom-lhha binding value" xmlns:xxbl="http://orbeon.org/oxf/xml/xbl">
    <metadata xmlns="http://orbeon.org/oxf/xml/form-builder">
        <display-name lang="en">Image Picker</display-name>
        <icon lang="en">
            <small-icon>/apps/fr/assets/img/camera.png</small-icon>
            <large-icon>/apps/fr/assets/img/camera.png</large-icon>
        </icon>
        <templates>
            <view>
                <fr:image-picker id="image-picker" ref="">
                    <xf:label ref=""/>
                    <xf:hint ref=""/>
                    <xf:help ref=""/>
                    <xf:alert ref=""/>
                </fr:image-picker>
            </view>
        </templates>
    </metadata>
    <xbl:template>
        <xh:label for=""><xf:output value="xxf:label('fr-image-picker')"/></xh:label>
        <xf:input ref="xxf:binding('fr-image-picker')" class="image-picker"/>
    </xbl:template>
</xbl:binding>

Any tips would be appreciated.

1

There are 1 best solutions below

0
On

Here is an example that defines a simple component with a binding and label support. When I use the component, I simply use a regular xf:label:

<xh:html
        xmlns:xh="http://www.w3.org/1999/xhtml"
        xmlns:xf="http://www.w3.org/2002/xforms"
        xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
        xmlns:fr="http://orbeon.org/oxf/xml/form-runner">
    <xh:head>
        <xf:model>
            <xf:instance>
                <form xmlns=""/>
            </xf:instance>
        </xf:model>
        <xbl:xbl xmlns:xbl="http://www.w3.org/ns/xbl" xmlns:xxbl="http://orbeon.org/oxf/xml/xbl">
            <xbl:binding element="fr|image-picker" id="fr-image-picker" xxbl:mode="lhha binding value" xmlns:xxbl="http://orbeon.org/oxf/xml/xbl">
                <xbl:template>
                    <xf:input ref="xxf:binding('fr-image-picker')"/>
                </xbl:template>
            </xbl:binding>
        </xbl:xbl>
    </xh:head>
    <xh:body>
        <fr:image-picker ref=".">
            <xf:label>My Label</xf:label>
        </fr:image-picker>
    </xh:body>
</xh:html>

If you want to use an external label with for, simply give an id to fr:image-picke and use for as usual:

<xf:label for="my-date-picker">My Label</xf:label>
<fr:image-picker id="my-date-picker" ref="."/>