cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco Share forms: how to define a custom validation-handler for a non-mandatory field?

mathias_lin
Star Contributor
Star Contributor
I have already read the Alfresco documentation as well as the wiki, but still it does not get clear: what's the proper way to define a custom validation-handler for a certain field in an Alfresco Share form?

The problem is that the approach that I found everywhere in the forum always overrides the MANDATORY type, so the validation handler only gets called if the field is set to mandatory="true".


<config evaluator="aspect" condition="my:aspect">
       <forms>
        <form>
            <field-visibility>
                <show id="my:property" />
            </field-visibility>
            <appearance>
                <field id="my:property" mandatory="true">
                    <constraint-handlers>
                        <constraint type="MANDATORY" validation-handler="Alfresco.forms.validation.myValidator" event="keyup" />
                    </constraint-handlers>
                </field>
            </appearance>
        </form>
    </forms>
</config>


But how to define a custom validation-handler for <strong>a field that is not mandatory</strong>? Or else, which is the correct type to choose/override? I tried
type="LENGTH"
instead, but this also does not get called when the user enters something in the form field and the field.
1 REPLY 1

zladuric
Champ on-the-rise
Champ on-the-rise
Is Javascript solution acceptable? If it is, you can create/add a form or field validators in your dashlet or component code.