cancel
Showing results for 
Search instead for 
Did you mean: 

How do I set maxLength of a string on an xforms template

harrymoore
Champ in-the-making
Champ in-the-making
Simple question: how do I set a limit on the lenth of an input string?

I found an example somewhere that showed how to use an xs:restriction but this does not appear to work:
<xs:simpleType name="string25">
    <xs:restriction base="xs:normalizedString">
         <xs:maxLength value="25"/>
    </xs:restriction>
</xs:simpleType>

<xs:element name="content_idx" type="string25" default="" minOccurs="1" maxOccurs="1">
     <xs:annotation>
         <xs:appinfo>
             <alf:alert>Content ID is required</alf:alert>
             <alf:label>Content ID</alf:label>
             <alf:appearance>minimal</alf:appearance>
        </xs:appinfo>
    </xs:annotation>
</xs:element>

Looks simple enough. Why doesn't it work?
5 REPLIES 5

arielb
Champ in-the-making
Champ in-the-making
i'll take a look at this - but the xforms processor should be validating the user entered string length against the schema and reporting it invalid if it's not valid.  are you looking for more of a ui side change?  do you want the textfield itself to be x chars long - because that's not implemented yet.

harrymoore
Champ in-the-making
Champ in-the-making
i don't really care, yet, about the size of the field on the form but i'm deploying the value to a database field VARCHAR(25) so I want to limit the input size of the field to 25 chars. How do I do that?

Thanks,

arielb
Champ in-the-making
Champ in-the-making
hmmm…. it looks like my xforms processor is not validating schema simple types rigorously.  i'll see if there's a switch that needs turning on - but it's possible that all these restrictions need to be turned into xforms constraints in order to get this to work which would be rather annoying.

harrymoore
Champ in-the-making
Champ in-the-making
So am I doing the right thing by "subclassing" the xs:normalizedString this way? Is this a best practice? I'm having trouble finding good docs/tutorials on xsd, xforms to know. I just stumbled upon this solution.

arielb
Champ in-the-making
Champ in-the-making
maxLength or length restrictions are the way to go.  in the next version these restrictions will be enforced by textfields at a minimum - and hopefully by the xforms processor if i can figure out how to get it to properly validate schema types consistently.