clientside validation not working

Dec 6, 2011 at 12:31 PM

Ive created a custom attribute and have it working sreverside, but i cant get it to work clientside.  Hers the attribute

public class DateIsGreaterThanAttribute : ModelAwareValidationAttribute
    {
        //this is needed to register this attribute with foolproof's validator adapter
        static DateIsGreaterThanAttribute() { Register.Attribute(typeof(DateIsGreaterThanAttribute)); }

        private string _propertyName;
        //propertyName is the name of the property to compare against in the model containing the attribute
        //eg  policyStartDate
        public DateIsGreaterThanAttribute(string propertyName) : base()
        {
            _propertyName = propertyName;
        }
        

        public override bool IsValid(object value, object container)
        {
            //use reflection to get at the underlying value of the specified model property
            PropertyInfo propertyInfo = container.GetType().GetProperty(_propertyName);
            object inspectionValue = propertyInfo.GetValue(container, null);
            if (inspectionValue == null || value == null)
            {
                return true;
            }
            DateTime dateLower = (DateTime)inspectionValue;//the date we compare against
            DateTime dateHigher = (DateTime)value;//the date entered
            return (dateHigher > dateLower);
        }
    }

it uses a value determined at runtime to compare against.  If i add this to my page, It just wont work

 

Sys.Mvc.ValidatorRegistry.validators["DateIsGreaterThan"] = function (rule) 
    {
        return function (value, context) 
        {
            var dependentProperty = foolproof.getId(context.fieldContext.elements[0], "PolicyStartDate");
            var dependentValue = document.getElementById(dependentProperty).value;
            //extra validation logic will go here
            return true;
        };
    };

 

this line is never reached

 

var dependentProperty = foolproof.getId(context.fieldContext.elements[0], "PolicyStartDate");

so it would seem that the "DateIsGreaterThan" validation entry in the JSON just isnt there

can anyone tell me what im doing wrong ?
Dec 6, 2011 at 1:40 PM

ive even tried registering it myself in global.asax and still nothing

 

Foolproof.Register.Attribute(typeof(DateIsGreaterThanAttribute));

 

Coordinator
Dec 6, 2011 at 1:43 PM

I answered in the other thread you started: http://foolproof.codeplex.com/discussions/281621