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

Reset RadDateTimePicker DateInput validation formatting

2 Answers 118 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
William
Top achievements
Rank 1
William asked on 30 May 2013, 10:47 PM
I am having an issue in clearing the contents of the DateInput box of a RadDateTimePicker via client-side javascript when invalid data has been entered.

In my scenario, I have two radio buttons (asp:RadioButton) that allow a user to select to either perform an action immediately or schedule the action for a future date/time.  The later radio button is coupled with a RadDateTimePicker.  If the user initially enters a date then switches to perform the action immediately, the RadDateTimePicker should be cleared.

If a valid date has been selected or entered, I am able to clear the contents with:

var dtTmPicker = $find("<%= SchedStartTime.ClientID %>");
dtTmPicker.clear();


However, if an invalid value has been entered for the date, the call to .clear() has no effect (because the underlying date value has not been set when the visible value is not valid).

Based on a few scattered forum posts, I have attempted to reset the invalid value, warning icon, and formatting on the field with:

var dtTmPicker = $find("<%= SchedStartTime.ClientID %>");
dtTmPicker.get_dateInput().set_textBoxValue(
"");
dtTmPicker.get_dateInput()._invalid =
false;
dtTmPicker.get_dateInput().updateCssClass();

This clears the text, but the warning icon and formatting remain.

Interestingly, I can set ._invalid=true and call .updateCssClass() to turn the validation icon/formattting on; and again set it to false to clear the validation icon/formatting.  But I can only do this when NO invalid value has been entered in the control.  Once an invalid value has been entered, I can only clear the text but not the icon/formatting.

Is there something else that needs to be done to clear the form and reset the validation?  Any help is greatly appreciated.


2 Answers, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 04 Jun 2013, 10:22 AM
Hello William,

Yes when the input holds invalid value, the .get_value() returns "". So clear("") does not do anything, since the input is already empty.

You can use the following approach to workaround this:

var dateInput = $find("<%= SchedStartTime.ClientID %>").get_dateInput();
dateInput._holdsValidValue=true;
dateInput.get_dateInput().clear();

Also from this release, you will be able to use client side set_invalid(false) method.

Regards,
Vasil
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
William
Top achievements
Rank 1
answered on 04 Jun 2013, 03:55 PM
Thank you for the reply, Vasil.  That works well.

As a workaround, I had figured out I could just set the field to a valid value immediately prior to clearing as follows:

var dtTmPicker = $find("<%= SchedStartTime.ClientID %>");
tmpDate = new Date();
dtTmPicker.set_selectedDate(tmpDate)
;
dtTmPicker.clear();

I prefer your method.  Thanks again.
Tags
Calendar
Asked by
William
Top achievements
Rank 1
Answers by
Vasil
Telerik team
William
Top achievements
Rank 1
Share this question
or