This is a migrated thread and some comments may be shown as answers.

RadDateInput - Can't tell error state.

1 Answer 121 Views
Input
This is a migrated thread and some comments may be shown as answers.
Sean Overman
Top achievements
Rank 1
Sean Overman asked on 18 Sep 2009, 09:52 PM
First let me lay out the situation.   I have a Date Field that is not required.  But I would like this field to still be validated when data is entered. So, therefore I'm using the RadDateInput field and a custom validator.

I tried to implement a solution by subscribing to the Error event, and keeping track of the state.  But the problem is that when it enters error state, then you clear the text box, you don't know that you "cleared" the error, and the form doesn't validate.

Here is the javascript i'm using:
        var invalidInput = false
 
        function OnValueChanged(sender, args) { 
            if (!(invalidInput && args.get_newValue() == "")) { 
                invalidInput = false
            } 
        } 
 
        function OnError(sender, args) { 
            invalidInput = true
        } 
 
        function CustomValidate(sender, args) { 
            if (invalidInput) { 
                args.IsValid = false
            } 
        }   

And my control:
<tel:RadDateInput runat="server" id="DOB" MinDate="1/2/1900"
    <ClientEvents OnValueChanged="OnValueChanged" OnError="OnError" /> 
</tel:RadDateInput> 
<asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="DOB" ClientValidationFunction="CustomValidate" ErrorMessage="*" ValidateEmptyText="true" /> 
 

So, is there a way to check to see if the RadDateInput control is in "Error" state (red w/ Exclamation)?

You can reproduce this by using the code attached and following these steps.
#1 Set the date to something invalid ("asdf")
#2 tab out ( notice the Telerik Error state and the custom validator message '*" )
#3 Submit the form. (notice the validation error)
#4 clear the textbox
#5 tab out (notice he Telerik error state has been cleared, but the validation error still persists)
#6 submit the form( it wont submit because the custom validator has not been cleared)

Any help in resolving the validator issue, or giving me a solution where the Data in the RadDateInput is still validated but stops the form from submitting w/ errors while still allowing an "empty" state where the data not "required".

Thanks,
Sean

1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 24 Sep 2009, 06:08 AM
Hi Sean,

You can check the errorcode, to see if this is a parse error, or out of bounds error. Additionally, what is the logic which you are handling via the custom validator? One possible option may be to remove the custom validator for the date input control, and validate the input manually, when the user tabs out - given that the logic is not too complex.

Sincerely yours,
Yavor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Input
Asked by
Sean Overman
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Share this question
or