WPF DatePicker Blackout date entered, prevent old value from being restored - wpf

When I use the WPF 4.0 DatePicker with blackout date (or min/max), and the user enters a date that is blacked out by typing it in, the DatePicker reverts back to the original value.
This behavior is not the best for entering dates. If you key in the wrong year and tab out, it reverts back to the old value.
I'd like to be able to handle the error in code instead of just reverting back to the old value.

Related

How to link DayPicker to existing input element

I'm using react-day-picker DayPicker (not DayPickerInput) and have an existing element I want to use to drive the date popup. I can't figure out how to pre-feed the date from the element to the calendar and highlight the given date. All the other functionality, e.g. capturing the user chosen date and populating the element are working fine. So if my input element has Nov 11, 2019, and I click on it, I want the popup to go to that date and show it as selected. The current behavior is that it shows the current month and date. I've tried to set the selectedDays={this.state.selectedDay}, but that doesn't seem to work. Note that I am new to reactjs, and this could be the gap in my understanding.
Thanks for any suggestions you may have.
Found at least one way to achieve the behavior I was looking for. There is a DayPicker property "initialMonth" that will display the current month. Note that this only needs to be populated only with year and month:
initialMonth = {new Date(selectedDate.getFullYear(), selectedDate.getMonth())}

Edit the date using DateTimePicker

I am able to edit month,date and year by using TAB or Arrow keys(MM-dd-yyyy). I have doubt is this possible to edit total date format at a time (not using tab key or any arrow keys).
No, I don't think this is possible. From Using the DateTimePicker Control
The DateTimePicker operates as a masked edit control for entering date and time values. Each part of the date or time is treated as a separate field within the edit portion of the control. As the user clicks on each field, it is highlighted and they can use the up and down arrow keys to increment or decrement the value of the field. The user can also type values directly into the control, where applicable.

DevExpress DateEdit repository editor date validation

If users are going to be typing dates as well as choosing from the dropdown calendar widget, where is the best event to trap the entered value, whether it was typed or picked, then warn users if the date fails some validation, and finally rollback the edit value to where it was if the user decides not to override the warning?
We need to allow dates in the past, but want to prevent accidental dates in the past, which typically occurs in the first few months of the new year after users have been accustomed to typing, say, 2011 for the entire year and then when the year changes to 2012, they type 2011 out of habit. So this validation would only be in effect for the first few months of the year, not year-round.
I don't see how to rollback the value in EditValueChanged. The args don't have a cancel option there. Is there another better event to do this that works with typed values and picked values?
Use the EditValueChanging event. It does have a Cancel event, along with NewValue and OldValue.
I prefer to use Validating event of Control, where i get CancelEventArgs with which you can set the value as well as the focus on the control. e.Cancel will set the focus on control.
eg:
if (txtName.Text == "")
{
txtName.ErrorText = "Client Name should not be blank.";
e.Cancel = true;
}

DateTimePicker resets day

I am using DateTimePicker with Australian date formatting set (dd/mm/yyyy)
The problem is when user enters a day which is outside of the month (mm), control resets that day to "1".
This obviously is a quite confusing obstacle for user - it's not natural to enter the month first and then enter the day [culture-wise]
Is there a way to disable this validation or postpone it till say,when control loses focus?
Thanks!
I've tried and I do not see anyway we can disable this for on micro-validation via the DateTimePicker's properties.
I know your frustration when the current date is "09/11/2009" (dd/MM/yyyy) and a user wants to enter "31/12/2009" via the keyboard from left to right.
Upon htting "31", it'll revert to "1" as Nov has only 30 days. It will show "2" if "32" is entered.
It forces the user to enter the month first followed by the day. I.e. entering in the direction of right, left, far-right.
My suggestion is use a more generic form of format like yyyy-MM-dd which though does not follow your regional/cultural format, still is easily understood by the user (or Aussie friends).
Another option might be to instantiate an edit control and overlay it on top of the date time picker's edit, and use the value to set the date time picker's value. Of course, you'll need to do some validation before doing the setting; and you'll also want to mimic the way the date time picker's edit field allows you to select the date, month and year individually.

Can I change the input behaviour of a DateTimePicker control?

The default input behaviour of the DateTimePicker when entering a date is like this:
YYYY(Right Arrow)MM(Right Arrow)DD
The user want to enter the date like this:
YYYYMMDD
Is there any simple way of modifying the input behaviour of the DateTimePicker so that is does behave like the user want it to?
TIA
Expanding on PoweRoy's answer. Use a textbox and a datetimepicker. Make the datetimepicker small (just as big as the drop down arrow) and place it next to (or even inside) the textbox. Then you hook the dropdown and closeup events of the datetimepicker to get the value to and from the editbox.
I don't know how you use the DateTimePicker but what about using a simple editbox? (and validate date when a date is entered)
DateTimePicker is mostly used to choose a date without entering any number.

Resources