Go Back   SmartClient Forums > Smart GWT Technical Q&A
Wiki Register Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 18th May 2011, 00:24
damend damend is offline
Registered Developer
 
Join Date: Mar 2011
Posts: 360
Default add validators and get validators not possible

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?
Reply With Quote
  #2  
Old 18th May 2011, 08:43
Isomorphic Isomorphic is offline
Administrator
 
Join Date: May 2006
Posts: 30,520
Default

It's already there.
Reply With Quote
  #3  
Old 19th May 2011, 04:01
damend damend is offline
Registered Developer
 
Join Date: Mar 2011
Posts: 360
Default

Nice, thanks
Reply With Quote
  #4  
Old 20th May 2011, 00:06
damend damend is offline
Registered Developer
 
Join Date: Mar 2011
Posts: 360
Default

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 ...

?
Reply With Quote
  #5  
Old 20th May 2011, 08:20
Isomorphic Isomorphic is offline
Administrator
 
Join Date: May 2006
Posts: 30,520
Default

It's a static method.

Validator.addValidatorDefinition("myCustomValidato rType", new Validator());

... then in a .ds.xml file ...

<field name="someName">
<validator type="myCustomValidatorType" ...
Reply With Quote
  #6  
Old 22nd May 2011, 22:28
damend damend is offline
Registered Developer
 
Join Date: Mar 2011
Posts: 360
Default

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..
Reply With Quote
  #7  
Old 23rd May 2011, 08:47
Isomorphic Isomorphic is offline
Administrator
 
Join Date: May 2006
Posts: 30,520
Default

That's simpler - just define a SimpleType that inheritsFrom the "text" built-in type, add the trim validator there, and use this type pervasively.
Reply With Quote
  #8  
Old 25th May 2011, 06:23
damend damend is offline
Registered Developer
 
Join Date: Mar 2011
Posts: 360
Default

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 ?
Reply With Quote
  #9  
Old 25th May 2011, 23:41
damend damend is offline
Registered Developer
 
Join Date: Mar 2011
Posts: 360
Default

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..
Reply With Quote
  #10  
Old 26th May 2011, 08:10
Isomorphic Isomorphic is offline
Administrator
 
Join Date: May 2006
Posts: 30,520
Default

Yes - see the docs for CustomValidator - you can both look at the DataSourceField and at a Map of properties defined on the <validator> tag.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search


© 2010,2011 Isomorphic Software. All Rights Reserved