Permalink
Fetching contributors…
Cannot retrieve contributors at this time
112 lines (103 sloc) 4.84 KB
<!--
Copyright (C) 2010 Orbeon, Inc.
This program is free software; you can redistribute it and/or modify it under the terms of the
GNU Lesser General Public License as published by the Free Software Foundation; either version
2.1 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
The full text of the license is available at http://www.gnu.org/copyleft/lesser.html
-->
<xbl:xbl xmlns:xh="http://www.w3.org/1999/xhtml"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
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
id="fr-phone-binding"
element="fr|us-phone"
xxbl:container="span"
xxbl:mode="lhha binding value"
xxbl:label-for="input">
<!-- Orbeon Form Builder Component Metadata -->
<metadata xmlns="http://orbeon.org/oxf/xml/form-builder">
<display-name lang="en">US Phone Number</display-name>
<display-name lang="es">Número telefónico de USA</display-name>
<display-name lang="fi">Puhelinnumero USA</display-name>
<display-name lang="fr">Téléphone US</display-name>
<display-name lang="ru">Телефон в формате США</display-name>
<display-name lang="de">US Telefonnummer</display-name>
<display-name lang="it">Numero di telefono US</display-name>
<display-name lang="nl">Amerikaans telefoonnummer</display-name>
<display-name lang="pt">Número de telefone EUA</display-name>
<display-name lang="sv">Telefonnummer i USA</display-name>
<icon>
<icon-class>fa fa-fw fa-phone</icon-class>
</icon>
<templates>
<!-- Value is valid if it is empty or if it matches a normalized string of 10 digits -->
<bind constraint=". = '' or matches(., '^\d{10}$')"/>
<view>
<fr:us-phone>
<xf:label ref=""/>
<xf:hint ref=""/>
<xf:help ref=""/>
<xf:alert ref=""/>
</fr:us-phone>
</view>
</templates>
</metadata>
<xbl:resources>
<xbl:style src="/xbl/orbeon/us-phone/us-phone.css"/>
</xbl:resources>
<xbl:template>
<xf:var name="binding"
value="xxf:binding('fr-phone-binding')"/>
<xf:var name="view"
value="xxf:is-control-readonly('fr-phone-binding') and property('xxf:readonly-appearance') = 'static'"/>
<xf:var name="formatted"
ref="$binding"
value="
for $v in string(.) return
if (matches($v, '^\d+$')) then
concat(
'(',
substring($v, 1, 3),
') ',
substring($v, 4, 3),
if (string-length($v) gt 6) then
'-'
else
'',
substring($v, 7)
)
else
$v"/>
<!-- Edit mode -->
<xf:group ref="$binding[not($view)]">
<xh:span class="input-append">
<xf:input
id="input"
xbl:attr="navindex navindex=tabindex"
ref="."
class="fr-width-10em"
xxf:maxlength="14"
xxf:format="$formatted"
xxf:unformat="
for $t in translate(xxf:trim(), '()*-[].#/'': ', '') return
if (matches($t, '^\d+$')) then
$t
else
.">
<xf:hint appearance="minimal">(555) 555-5555</xf:hint>
</xf:input>
<xh:span class="add-on"/>
</xh:span>
</xf:group>
<!-- View mode -->
<xf:input ref="$binding[$view]" xxf:format="$formatted"/>
</xbl:template>
</xbl:binding>
</xbl:xbl>