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

RadDatePicker validation issue on second validation

3 Answers 94 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Stephan
Top achievements
Rank 1
Stephan asked on 13 Nov 2010, 01:12 AM
I have a RadDatePicker control on a form and I use the following script to reset the form fields after I save the data through an AJax call:

$.fn.clearForm = function () {
    return this.each(function () {
        var type = this.type, tag = this.tagName.toLowerCase();
        if (tag == 'form' || tag == 'div'||tag=='tr'||tag=='td')
            return $(':input', this).clearForm();
        if (type == 'text' || type == 'password' || tag == 'textarea')
            this.value = '';
        else if (type == 'checkbox' || type == 'radio')
            this.checked = false;
        else if (tag == 'select')
            this.selectedIndex = '';
    });
};

If after filling out the form and saving it I clear the fields, using the above jQuery script, the required field validation I have set up for the RadDatepicker fires even if you select a date. If I try the isEmpty() client call on the control it returns false so it does have a value. If you type a date manually in the input field in stead of selecting it through the calendar the required field validation does not fire.
The problem is obviously the script I use to clear the form fields as it works fine if I do not reset the fields. Can you tell me how I could/should go about this?

3 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 18 Nov 2010, 01:51 PM
Hello Stephan,

Can you send us the whole page code so we can test your scenario locally and perform further investigation on the issue?

Looking forward your reply,
Iana
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Stephan
Top achievements
Rank 1
answered on 18 Nov 2010, 06:44 PM
Below is sample code you can use to replicate the issue.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TelerikTest._Default" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
 
<script type="text/javascript">
    // This function is to clear a form clientside
    $.fn.clearForm = function () {
        return this.each(function () {
            var type = this.type, tag = this.tagName.toLowerCase();
            if (tag == 'form' || tag == 'div' || tag == 'tr' || tag == 'td')
                return $(':input', this).clearForm();
            if (type == 'text' || type == 'password' || tag == 'textarea')
                this.value = '';
            else if (type == 'checkbox' || type == 'radio')
                this.checked = false;
            else if (tag == 'select')
                this.selectedIndex = '';
        });
    };
 
    // This function validates the form and if validated resets the form
    function clearForm() {
        var validated = Page_ClientValidate("test");
        if (validated) {
            jQuery('#testform').clearForm();
        }
    }
</script>
 
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div id="testform">
        <p>
            Select a date and click submit. The form is reset. Select a date again and submit,
            this time the required field validator reports an error.
        </p>
        Date:
        <telerik:RadDatePicker ID="RadDatePicker1" runat="server">
        </telerik:RadDatePicker>
        <div>
            <asp:RequiredFieldValidator ID="reqDate" runat="server" ErrorMessage="Please select a date"
                ControlToValidate="RadDatePicker1" ValidationGroup="test" Display="Dynamic"></asp:RequiredFieldValidator>
            <div>
                <span id="submit" onclick="clearForm();">Submit</span>
            </div>
    </form>
</body>
</html>
0
Tsvetina
Telerik team
answered on 23 Nov 2010, 02:57 PM
Hi Stephan,

Could you please confirm which version of RadControls you are using? I tried replicating the issue in an empty project using the latest version and could not reproduce the erroneous behavior. You can find the sample web site attached to this post.

Best wishes,
Tsvetina
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Calendar
Asked by
Stephan
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Stephan
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or