views:

22

answers:

0

The following code was working on FF and on IE8. Now (regular Win-updates) IE freezes as soon as it tries to apply any part of either or both rulesets for ev_starttime and ev_endtime. IE CPU usage shoots to 50%, but memory usage is not affected. There are no error messages from either browser (using Firebug for FF and IE Developer Tools for IE). From the CPU usage change, I'm thinking that IE is getting stuck in a loop, but it's not a loop anyone else can see. Ideas?

$("form[name='event_form']").validate({
    debug: true,
    rules: {
        title: {required:true, minlength:5},
        description: {required:true, minlength:5},
        event_type_id: "required",
        ev_start: { dateCan: true, required: true},
        ev_end:{ dateCan: true,
                 minDate: "input[name='ev_start']"
        },
        ev_starttime:{
            required: 
                function(element){
                    return $("input[name='allday']:unchecked");
                },
            time: true,
            maxTime: {
                depends: function(element) {
                            return $("input[name='ev_endtime']:filled")
                                   && $("input[name='ev_start']").valid()   
                                   && $("input[name='ev_end']").valid()
                                   && $("input[name='ev_start']").val()==$("input[name='ev_end']").val();
                        },
                param: "input[name='ev_endtime']"
            }
        },
        ev_endtime:{
            required: 
                function(element){
                    return $("input[name='allday']:unchecked")  
                },
            time: true,
            minTime: {
                depends: function(element) {
                            return $("input[name='ev_start']").valid()
                                   && $("input[name='ev_end']").valid()
                                   && $("input[name='ev_starttime']").valid()
                                   && $("input[name='ev_start']").val()==$("input[name='ev_end']").val();
                        },
                param:  "input[name='ev_starttime']"
            }

        }
    }
});

minTime and maxTime rules look like this:

jQuery.validator.addMethod("minTime", function(value, element, param) {
        try {
            var aftertime=value.split(':');//hours and minutes

            if($(param).val()=='') throw($param.name + ' empty');
            var beforetime=$(param).val().split(':');

            var at=new Date(0,0,0,aftertime[0],aftertime[1]*1);
            var bt=new Date(0,0,0,beforetime[0],beforetime[1]*1);

            return this.optional(element) || at > bt;
        } catch(err){
            return false;
        }
    }, function(param){
        return "Time must occur after " + $(param).val();
    }
);

jQuery.validator.addMethod("maxTime", function(value, element, param) {
        try {
            var beforetime = value.split(':');//hours and minutes

            if($(param).val()=='') throw($param.name + ' empty');
            var aftertime =$(param).val().split(':');

            var at=new Date(0,0,0,aftertime[0],aftertime[1]*1);
            var bt=new Date(0,0,0,beforetime[0],beforetime[1]*1);

            return this.optional(element) || at > bt;
        } catch(err){
            return false;
        }
    }, function(param){
        return "Time must occur before " + $(param).val();
    }
);