cancel
Showing results for 
Search instead for 
Did you mean: 

constraints on values entered in xforms

boneill
Star Contributor
Star Contributor
Hi All,

Can anyone tell me how to limit the number of characters a user can enter when using a xs:normalizedString.  On a broader topic is there a generic way to add a constraint to the values entered for an xform field.

Regards
2 REPLIES 2

pmonks
Star Contributor
Star Contributor
XML Schema has a reasonably rich constraint vocabulary, which can be used to do this kind of thing (see http://www.w3schools.com/schema/schema_facets.asp, for example).  For controlling the minimum and maximum lengths of string values, try the "minLength" and "maxLength" facets.

Cheers,
Peter

boneill
Star Contributor
Star Contributor
Thanks Peter,  I did some work on this and got it to work.  I post the examples below in case anyone else needs to get this working and has limited experience in xforms & annotataions like myself:


Constrain a user field to 20 characters and display error message in message pain if this is violated on form submission:



<xs:simpleType name="string20">
     <xs:restriction base="xs:normalizedString">
       <xs:maxLength value="20"></xs:maxLength>
     </xs:restriction>
</xs:simpleType>

<xs:element name="title" type="hp:string20" default="" minOccurs="1" maxOccurs="1">
       <xs:annotation>
   <xs:appinfo>
                <alf:alert>Title required (max length 20 characters).</alf:alert>
               </xs:appinfo>
        </xs:annotation>            
</xs:element>


Another example constraint is shown using the anyURI .  The file picker will open in the finance products folder (finance products folder is at /Root/finance products).  Also constrained so that only html pages are opened.


In the xform schema

<xs:element name="link_to" type="xs:anyURI">
        <xs:annotation>
             <xs:appinfo>
                <alf:appearance>folder_restricted_file_picker_finance_products</alf:appearance>
             </xs:appinfo>
         </xs:annotation>
</xs:element>

in the  web-client-config-wcm.xml file:

<!– File Picker for the Homes Page Finance Product pages –>
<widget xforms-type="xf:upload" appearance="folder_restricted_file_picker_finance_products"
                   javascript-class-name="alfresco.xforms.FilePicker">
             <param name="selectable_types">wcm:avmcontent,wcm:avmfolder</param>
       <param name="filter_mimetypes">text/html</param>
             <param name="folder_restriction">finance products</param> 
</widget>
 

Hope this is useful to someone.
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.