|
#1
|
|||
|
|||
|
To add validators on the client, it would be very useful to have a function like addValidators(). This is needed to add global validators( like a trim functionality) afterwards for all text fields for example.
There is also a getValidators() needed, to check, if validators are there on generated fields, or do a formItem.setValidator(formItem.getValidators() . Can you intruduce a function like this? |
|
#2
|
|||
|
|||
|
It's already there.
|
|
#3
|
|||
|
|||
|
Nice, thanks
|
|
#4
|
|||
|
|||
|
And how to use it?
Lets say I have FormItem item = new FormItem(); item.setValidator(new MaskValidator()); // later on item.setValidator(new Validator().addValidatorDefinition("newvalidator", new Validator())); or item.setValidator(item.getValidators().addValidato rDefinition ... ? |
|
#5
|
|||
|
|||
|
It's a static method.
Validator.addValidatorDefinition("myCustomValidato rType", new Validator()); ... then in a .ds.xml file ... <field name="someName"> <validator type="myCustomValidatorType" ... |
|
#6
|
|||
|
|||
|
Lets say I want to add a Trim-Validator, which iterates through all textfields, but all existing validators should work like before.
Is Validator.addValidatorDefinition("myCustomValidato rType", new Validator()); meant for something like that? I would prefer setting validators in my java code, without using the .ds.xml file, otherwise we need to set every validator we use on fields in the .ds.xml. Besides I want to set clientside validators related to the types of the datasourcefields. Is there another solution you are offering? Last edited by damend; 23rd May 2011 at 05:03.. |
|
#7
|
|||
|
|||
|
That's simpler - just define a SimpleType that inheritsFrom the "text" built-in type, add the trim validator there, and use this type pervasively.
|
|
#8
|
|||
|
|||
|
I did so. With this, both validators are executed. Nice !
There is one issue left: The trim validator (used on the SimpleType) will change the value so that it will be trimmed, but it seems like the second customvalidator will use the original value without trimming. But the trimmed value has to be validated by the second validator, not the values before trimming. Do you have a solution for me ? |
|
#9
|
|||
|
|||
|
And:
1.) SimpleType validation will be executed on the client only, (if I don't execute a validation on the server explicity) a custom validator, which is registered with Validator.addValidatorDefinition("myCustomValidato rType", new Validator()); and defined in the ds.xml, correct? 2.) Is it possible to pass arguments to custom defined validators in the datasource-definitionfile? How does the code looks like? Is there an example? Last edited by damend; 26th May 2011 at 00:08.. |
|
#10
|
|||
|
|||
|
Yes - see the docs for CustomValidator - you can both look at the DataSourceField and at a Map of properties defined on the <validator> tag.
|