Hi,
I'm looking for a way to detect that a user has keyed in an invalid date into a date time picker control where having a blank/nullable date IS valid. Currently, I cannot tell the difference (looking at a model object) if a user cleared the date or typed the word "dog" into the text box rather than a valid date format because both appear as null. I've tried using the element's change event, but it doesn't fire if the initial value is null (blank), which makes since if it evaluates "dog" as a null (there would be no change for its initial value of null).
I thought perhaps a validator was the correct way of handling this. When I change an item in my observable array the change event is fired by the array, I then called myValidator.validate() method, but it always returns true. Also, the validator itself runs AFTER the observable array's change method. Since myValidator.validate() returned true, I save the data to the server. Once the validator does fire, it validates the date field and thinks it is invalid. This leaves me with a word like "dog" sitting in my date time picker and a null getting sent to the server.
How can I tell my user that "dog" isn't a proper date and prevent it from going to the server?
Dave
I'm looking for a way to detect that a user has keyed in an invalid date into a date time picker control where having a blank/nullable date IS valid. Currently, I cannot tell the difference (looking at a model object) if a user cleared the date or typed the word "dog" into the text box rather than a valid date format because both appear as null. I've tried using the element's change event, but it doesn't fire if the initial value is null (blank), which makes since if it evaluates "dog" as a null (there would be no change for its initial value of null).
I thought perhaps a validator was the correct way of handling this. When I change an item in my observable array the change event is fired by the array, I then called myValidator.validate() method, but it always returns true. Also, the validator itself runs AFTER the observable array's change method. Since myValidator.validate() returned true, I save the data to the server. Once the validator does fire, it validates the date field and thinks it is invalid. This leaves me with a word like "dog" sitting in my date time picker and a null getting sent to the server.
How can I tell my user that "dog" isn't a proper date and prevent it from going to the server?
Dave