cancel
Showing results for 
Search instead for 
Did you mean: 

Text Field Mask

gabri124
Champ in-the-making
Champ in-the-making
Hello i'm trying to search an example to create a text field mask. The problem is that i have a textfield that must be a 5 digits field, but it isn't mandatory then i dont know how to manage it (i ussually create events functions on mandatory fields to control mask).
How can i manage to create a mask for a field and dont use events functions?

Can you help me?

Thx
6 REPLIES 6

ltardioli
Champ in-the-making
Champ in-the-making
You could set this on control-param in your share-config-custom.xml;

<field id="my:field">
                  <control template="/org/alfresco/components/form/controls/textfield.ftl">
                     <control-param name="maxLength">5</control-param>
                     <control-param name="size">5</control-param>
                  </control>
</field>

gabri124
Champ in-the-making
Champ in-the-making
Thx Itardiol, i have code this change, but this form field doesn't control that user uses only numbers, that's why the reason to try to create a mask

ltardioli
Champ in-the-making
Champ in-the-making
So, in this case you could do this by change your model definition creating a constraint:


<constraints>
        <constraint name="my:customContraint" type="REGEX">
         <parameter name="expression"><value>Here goes your  regular expression that allows only numbers</value></parameter>
         <parameter name="requiresMatch"><value>true</value></parameter>
   </constraint>
</constraints>

And in your property definition:

<property name="my:field">
               <title>My Field</title>
               <type>d:text</type>
               <constraints>
                  <constraint ref="my:customContraint" />
               </constraints>
            </property>

With this constraint you allow only numbers in your field and with first solution that I said you set the size of the field;

I think that regular expression is something like this: ^[0-9]+$ but I'm not sure.

Try this and let me know 😃

ltardioli
Champ in-the-making
Champ in-the-making
I almost forgot that you can do a size definition setting a constraint too:

<constraint id="my:lengthCont" type="LENGTH">
                    <parameter name="minLength"><value>0</value></parameter>
                    <parameter name="maxLength"><value>5</value></parameter>
</constraint>

gabri124
Champ in-the-making
Champ in-the-making
thx i will try this solution  Smiley Happy

gabri124
Champ in-the-making
Champ in-the-making
I have try this option, but when i write a number i loose the field focus, and this occurs everymoment Smiley Sad

I think that may be i will create a new textfield template that mandataroy attribute will not paint * in the field form