Show error warning in RadDateInput from Javascript

8 posts, 0 answers
  1. Richard M
    Richard M avatar
    76 posts
    Member since:
    Mar 2010

    Posted 29 Dec 2010 Link to this post

    Is there a way or method for displaying the error message/warning for RadDateInput1 from a Javascript function?  For example, the user does not enter a value in RadDateInput1, and my Javascript function returns dateInput.get_SelectedDate = null; return false;  - so it doesn't postback to the server.  But I would like my RadDateInput1 to show the user that they need to add/change a value by displaying the error you would normally get if you entered a value that was not a date.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 30 Dec 2010 Link to this post

    Helo Richard,

    Attach OnError client-side event handler which is called when the input control detects that the user has tried to enter an invalid value. See the example shown below.

    [ASPX]
     
    <telerik:raddatepicker id="RadDatePicker1" runat="server"
      <DateInput> 
         <ClientEvents OnError="OnError" /> 
      </DateInput> 
    </telerik:raddatepicker> 

    [JavaScript]
     
    <script type="text/javascript"
    function OnError(sender, eventArgs) 
        if(eventArgs.get_reason()==1) 
        { 
            alert("Invalid date entered"); 
        } 
     </script> 

    -Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Richard M
    Richard M avatar
    76 posts
    Member since:
    Mar 2010

    Posted 30 Dec 2010 Link to this post

    Is there a way that I can display the error in the RadDateInput itself, as in the attached picture, instead of a javascript alert?
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 31 Dec 2010 Link to this post

    Hello,

    By default, RadDateInput shows error icon if the date typed is invalid. And if you want to customize the appearance of the invalid style, then use the InvalidStyle property.

    <telerik:RadDateInput ID="RadDateInput1" runat="server">
                 <InvalidStyle BackColor="Red" />
    </telerik:RadDateInput>


    -Shinu.
  6. Richard M
    Richard M avatar
    76 posts
    Member since:
    Mar 2010

    Posted 03 Jan 2011 Link to this post

    The error message does show by default if you type in an incorrect format.  But it the error message does not show if the user leaves the field blank.  I would like to show that error if they leave it blank.  Is there a way to do that in Javascript?
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 04 Jan 2011 Link to this post

    Hello Richard,

    You can use the client method _invalidate() to show the error message explicitly. Here is a sample code which shows the error invalid input when the user leaves the field blank.

    JavaScript:
    function OnBlur(sender, args)
       {
           if (sender.isEmpty())
          {
               sender._invalidate();
               sender.updateCssClass()
           }
       }

    Shinu.
  8. Howard
    Howard avatar
    2 posts
    Member since:
    Dec 2014

    Posted 15 Jan 2015 in reply to Shinu Link to this post

    I can't get any of this stuff to work. Very frustrating.
  9. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 16 Jan 2015 Link to this post

    Hi Howard,

    This markup should work for you:
    <script type="text/javascript">
        function blurHandler(sender, args) {
            if (!sender.get_value()) sender.set_invalid(true);
        }
    </script>
    <telerik:RadDatePicker runat="server" ID="RadDatePicker1">
        <DateInput ClientEvents-OnBlur="blurHandler"></DateInput>
    </telerik:RadDatePicker>


    Regards,
    Vasil
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017