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

DatePicker client validation before update

3 Answers 484 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dmitry
Top achievements
Rank 1
Dmitry asked on 13 Sep 2011, 02:03 PM
Hello,
Each time I enter wrong data into date picker, I see a exclamation sign, but this won't prevent me to press "Update" and save data, although it wouldn't be saved correctly. Is there a way to perform validation of date picker value in clientside OnCommand function? Automatic CRUD operations are disabled, I save all data manually.
BTW, it would be nice if you add clientside is_valid() function to each AJAX control. This could look like
function onGridCommand(s, a) {
   e.set_cancel(!datePicker.is_valid());
}

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 13 Sep 2011, 02:46 PM
Hello Dmitry,

Try the following approach to achieve you scenario.
aspx:
<telerik:GridTemplateColumn HeaderText="" UniqueName="Delete" AllowFiltering="false">
    <ItemTemplate>
      <asp:TextBox ID="txt1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "EmployeeID")%>' Style="display: none"></asp:TextBox>
    </ItemTemplate>
    <EditItemTemplate>
      <telerik:RadDatePicker ID="DatePicker1" runat="server" DateInput-ClientEvents-OnBlur="OnBlur"></telerik:RadDatePicker>
      <asp:RequiredFieldValidator ID="Req1" runat="server" ErrorMessage="Select Date" ControlToValidate="DatePicker1">
         </
asp:RequiredFieldValidator>
    </EditItemTemplate>
</telerik:GridTemplateColumn>

Client side:
function OnBlur(sender, args)
{
  if (sender._invalid) //checking whether the entered date is valid or not
  {
    sender.clear();
  }
}

Thanks,
Shinu.
0
Dmitry
Top achievements
Rank 1
answered on 20 Sep 2011, 12:22 PM
Thank you.
You just missed a function call. Not sender._invalid but sender.get_dateInput()._invalid
0
Dmitry
Top achievements
Rank 1
answered on 20 Sep 2011, 01:55 PM
Hello again,
I have discovered something looking like a bug :)
I'm using inplace editing following scenario described here. For example, I have a date of 01.01.2012 in date picker. I erase zero from year value (year becomes 212) and click next row to save data. In this case picker.get_dateInput()._invalid is true. But when I try to press TAB after erasing zero, _invalid value is false. Textbox is bordered red in both cases. Any ideas?
Tags
Grid
Asked by
Dmitry
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Dmitry
Top achievements
Rank 1
Share this question
or