CastleValidator - Multiple rules for DateTime, Integer

Aug 31, 2009 at 1:35 AM

hi,

i am using castle validator. if i decorate my property with "DateValidator" or "IntegerValidator" attribute, "Required" rule is added in the client side even though the property is not decorated with "Required" attribute. when i looked into the source for CastleValidatorRulesProvider i find that for Date, DateTime and Integer multiple rules are added to the rule emitters hence required rule is added in the client side. i guess there's a reason behind that but can't really figure it out. anyone has any idea about that?

thanks

 

 

 

 

 

Coordinator
Sep 13, 2009 at 5:44 PM

The reason is that those types are value types - they can't be null - so it would be meaningless to accept blank input (what value would you use for the property in that case?).

If you want your property to be optional, mark it as nullable, e.g. int? or DateTime?. That makes it possible for the property to hold "null" if no value is supplied, so then xVal won't treat it as required.

Regards

Steve