1
votes

I want to create a custom XBL component for Orbeon Form Builder that would contain an input text and validate it.

I've managed to create the component and add it to the Form Builder sidebar, but I can't figure out how to do the validation.

The validation I'm looking to do is kind of complex, it's similar to a credit card, some digits have special significance and then there's a checksum that needs to be computed and validated.

What I have so far is this:

<xbl:xbl xmlns:xf="http://www.w3.org/2002/xforms"
         xmlns:ev="http://www.w3.org/2001/xml-events"
         xmlns:xbl="http://www.w3.org/ns/xbl"
         xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"
         xmlns:fb="http://orbeon.org/oxf/xml/form-builder"
         xmlns:my="http://example.com/xbl">

    <xbl:binding element="my|component" id="my-component" xxbl:mode="lhha binding value">
        <metadata xmlns="http://orbeon.org/oxf/xml/form-builder">
            <display-name lang="en">Component</display-name>
            <icon lang="en">
                <small-icon>/forms/orbeon/builder/images/input.png</small-icon>
                <large-icon>/forms/orbeon/builder/images/input.png</large-icon>
            </icon>
            <templates>
                <view>
                    <xf:input id="" ref="" xmlns="">
                        <xf:label ref=""/>
                        <xf:hint ref=""/>
                        <xf:help ref=""/>
                        <xf:alert ref=""/>
                    </xf:input>
                </view>
            </templates>
        </metadata>
    </xbl:binding>
</xbl:xbl>
1

1 Answers

1
votes

You can place a validation template in the metadata, at the same level as <view>, but using <bind>. For example:

<bind
    type="xf:integer"
    constraint="...some XPath expression here..."/>

You could omit the xf:integer type if the value is otherwise validated by the constraint.

With constraint, you should be able to validate your checksum.

If part of your value follows the same rules as credit cards, you could use the standard is-card-number() function as a helper.