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

Disable RadDatePicker and RadTimePicker Default Validation in WPF

3 Answers 675 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Mathew
Top achievements
Rank 1
Mathew asked on 13 Jul 2011, 10:06 AM
Hello,

I'm using xaml, view model and validation rule in C#

The RadDatePicker has default validation for any invalid date. 

In my xaml, I have my own validation rule for RadDatePicker and RadTimePicker with this Style of my ControlTemplate to display the error. (please see the xaml code below the for the Control Template Style and my validation rule)

We allow the user to put nothing or empty string in the DatePicker unless we set it to mandatory that will use our validation rule to output a customized error style and message.In our validation rule, if we want to raise the error, it will use this code "return new ValidationResult(false, ErrorMessage);" However, since the default validation of RadDatePicker or RadTimePicker, it still set show the default error even the validation rule switches off the validation with this line  "return new ValidationResult(true, null);"

 Is there way I can disable the default behaviour and implement the custom behaviour I have?

Thanks.

Jason

====  Style of my ControlTemplate ==========

<ControlTemplate x:Key="validationTemplate">
                <DockPanel>
                    <TextBlock Foreground="Red" FontSize="20">!</TextBlock>
                    <AdornedElementPlaceholder/>
                </DockPanel>
            </ControlTemplate>
            <Style x:Key="radDatePicker" TargetType="{x:Type telerik:RadDatePicker}">
                <Style.Triggers>
                    <Trigger Property="Validation.HasError" Value="true">
                        <Setter Property="ToolTip"
              Value="{Binding RelativeSource={x:Static RelativeSource.Self},
                              Path=(Validation.Errors)[0].ErrorContent}"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
            <Style x:Key="radTimePicker" TargetType="{x:Type telerik:RadTimePicker}">
                <Style.Triggers>
                    <Trigger Property="Validation.HasError" Value="true">
                        <Setter Property="ToolTip"
              Value="{Binding RelativeSource={x:Static RelativeSource.Self},
                              Path=(Validation.Errors)[0].ErrorContent}"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
  
=================================================

==== xaml code to my validation rule ==========

 <telerik:RadDatePicker.SelectedDate>
                        <Binding Path="CommercialStartDateSelectedDate"
                                     UpdateSourceTrigger="PropertyChanged"
                                     Mode="TwoWay"
                                     >
                            <Binding.ValidationRules>
                    <common:MandatoryValidationRule
                                   
                                            ValidatesOnTargetUpdated="False"
                                            FieldName="CommercialStartDate" InstanceId="{common:DataResourceBinding DataResource={StaticResource commercialLayoutDesignInstanceId}}" IsMandatory="{common:DataResourceBinding DataResource={StaticResource commercialStartDateIsMandatory}}" ErrorMessage="{x:Static local:Globalization.CommercialStartDateMandatoryErrorMessage}" >
                    </common:MandatoryValidationRule>

                    <common:RecommendedValidationRule
                                            ValidatesOnTargetUpdated="False"
                                            IsRecommended="{common:DataResourceBinding DataResource={StaticResource commercialStartDateIsRecommended}}" ErrorMessage="{x:Static local:Globalization.CommercialStartDateRecommendedErrorMessage}" >
                    </common:RecommendedValidationRule>
                </Binding.ValidationRules>


Thanks,

3 Answers, 1 is accepted

Sort by
0
Pana
Telerik team
answered on 15 Jul 2011, 09:03 AM
Hello Martin,

I am not sure I understand you well but from your description it sounds like you need to set the:

Validation.ErrorTemplate="{x:Null}"

On the RadDateTimePicker so the default red border does not appear.

Kind regards,

Pana
the Telerik team

 

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Piyush
Top achievements
Rank 1
commented on 17 Jan 2022, 12:39 PM

i have written the same as above but radtime picker still shows validation(red border) on empty string 
can you pls help


<telerik:RadDateTimePicker x:Name="endTimePicker" 
                                                               Margin="5,0"
                                                               HorizontalAlignment="Center" VerticalAlignment="Center"
                                                               DateTimeWatermarkContent="{Binding TimePickerWatermark, Source={StaticResource GstWorklistFilterResources} }"
                                                               InputMode="TimePicker"
                                                               
                                                               TimeInterval="1:00" 
                                                               Validation.ErrorTemplate="{x:Null}"
                                                               SelectedTime="{Binding EndOrderForDateTime, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=False}"
                                                               IsEnabled="{Binding EndOrderForDateDisplayText, Converter={StaticResource NullOrEmptyToVisibilityConverter}}"
                                                               >

 

Stenly
Telerik team
commented on 20 Jan 2022, 11:02 AM

I am not sure that I fully understand the wanted result. Could you provide a bit more information on this matter? More specifically, is there any used validation rule? Also, if you could isolate it in a sample project it will greatly help, as I would be able to try and provide a suitable solution to this matter. 
0
Deloris
Top achievements
Rank 1
answered on 05 Jan 2015, 10:29 PM
I need to be able to turn the validation process off in the DateTimePicker control.
--------------------------------------------------------------------------------------------------------------

I have a similar issue. We have functionality in our application that allows the user to enter "t" or "h" in the date time picker to indicate the desire to use the current date or time. We have created a custom validation class that works well for this with the telerik control. However, we also allow our users to create macros that record groups of control with predetermined data entry information. Prior to switching to the Telerik control, if "t", for example was entered into the date time pick in a macro recording session, the "t" would remain in that space. The result is that when that macro was run, the "t" would be converted to the current date and time. Inherently, the Telerik control does validations that will, for example, convert the "Tuesday" into the next available date for Tuesday. In our case, because the "t" has a custom validation associated with it, it automatically convert to the current date. If I remove our custom validation, it returns an error because the Telerik validation system does not understand "t". I need to be able to turn this validation process off if it is determined that the user is currently recording a macro. I need to the field to allow the "t" to just exist.
0
Kalin
Telerik team
answered on 08 Jan 2015, 08:28 AM
Hello Deloris,

By Default Validation do you mean the parsing validation? You won't be able to remove, but you can change the parsing logic by implementing a custom parsing as demonstrated in the following article:
http://docs.telerik.com/devtools/wpf/controls/raddatetimepicker/how-to/implement-custom-parsing

However you won't be able to keep the entered input if the control loses the focus - it will parse the input somehow at that moment.

Hope this helps.

Regards,
Kalin
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.

 
Tags
DatePicker
Asked by
Mathew
Top achievements
Rank 1
Answers by
Pana
Telerik team
Deloris
Top achievements
Rank 1
Kalin
Telerik team
Share this question
or