How do I make sure the user enters an end date that is greater than or equal to the start date, not before?
Solved! Go to Solution.
You cannot prevent, in the date picker control, that the user select a date outside a certain date range (you can only limit the date picker based on the year). Please consider creating a new feature request in the PowerApps Ideas board for this scenario.
What you can do is to show a visual indication to the user that the selection is incorrect. In the example below, I added a label under the start / end date pickers and changed the border color of the pickers to indicate an error:
You can accomplish that by setting the following properties (assuming the start / end date picker controls are called respectively datePickerStart / datePickerEnd, and the label that shows the error is called labelInvalidDates):
datePickerStart.BorderColor: If(datePickerEnd.SelectedDate < datePickerStart.SelectedDate, Color.Red, RGBA(101, 128, 187, 1)) datePickerEnd.BorderColor: If(datePickerEnd.SelectedDate < datePickerStart.SelectedDate, Color.Red, RGBA(101, 128, 187, 1)) labelInvalidDates.Visible: datePickerEnd.SelectedDate < datePickerStart.SelectedDate
If the selection is fixed, then the label will disappear, and the border of the date picker controls will return to its default value:
Hope this helps!
You can use the DisplayMode property of the submit button to disable it if there are any errors in the form. For example, if you have the start/end dates and also a text input for the name that needs to have at least 5 characters, you can set the following expression to the DisplayMode property of the submit button:
If( (datePickerEnd.SelectedDate < datePickerStart.SelectedDate) || Len(textInputName) < 5), DisplayMode.Disabled, DisplayMode.Edit)
If either the dates are incorrect, or the length of the name is less than 5, then the submit button will be disabled; otherwise it will be active (DisplayMode.Edit means that the control can interact with the user).
You cannot prevent, in the date picker control, that the user select a date outside a certain date range (you can only limit the date picker based on the year). Please consider creating a new feature request in the PowerApps Ideas board for this scenario.
What you can do is to show a visual indication to the user that the selection is incorrect. In the example below, I added a label under the start / end date pickers and changed the border color of the pickers to indicate an error:
You can accomplish that by setting the following properties (assuming the start / end date picker controls are called respectively datePickerStart / datePickerEnd, and the label that shows the error is called labelInvalidDates):
datePickerStart.BorderColor: If(datePickerEnd.SelectedDate < datePickerStart.SelectedDate, Color.Red, RGBA(101, 128, 187, 1)) datePickerEnd.BorderColor: If(datePickerEnd.SelectedDate < datePickerStart.SelectedDate, Color.Red, RGBA(101, 128, 187, 1)) labelInvalidDates.Visible: datePickerEnd.SelectedDate < datePickerStart.SelectedDate
If the selection is fixed, then the label will disappear, and the border of the date picker controls will return to its default value:
Hope this helps!
Thank you for your help! This works good but unfortunately it still lets you submit even when the fields are red because of wrong dates. How can I stop it from submitting?
For that matter, how do you stop it from submitting on any error?
You can use the DisplayMode property of the submit button to disable it if there are any errors in the form. For example, if you have the start/end dates and also a text input for the name that needs to have at least 5 characters, you can set the following expression to the DisplayMode property of the submit button:
If( (datePickerEnd.SelectedDate < datePickerStart.SelectedDate) || Len(textInputName) < 5), DisplayMode.Disabled, DisplayMode.Edit)
If either the dates are incorrect, or the length of the name is less than 5, then the submit button will be disabled; otherwise it will be active (DisplayMode.Edit means that the control can interact with the user).
been trying to do that...but nothing working....... doing a similar thing in my project working on
Worx very well....thx a lot
Hi,
i have a similar date validation scenario but im using datetime picker controls instead of simple dates.
SO when i apply the logic as pasted above, it doesnt validate on the change. in other words teh validation does run on the change that i do or after i fix teh date value. so my error label continues to show and even teh border color
formula used -
If(ThisItem.'Start Time' > ThisItem.'End Time', Color.Red, RGBA(101, 128, 187, 1))//RGBA(0, 18, 107, 1)
error label.visbile property set to = If('End Time_DataCard4'.BorderColor=Red,true,false)
ANy suggestions if is there any OnChange property that i should fix too. ( Although i tried that on the HourValue and DateValue cards, but to no luck)
validation isnt re-running when i change teh picker control values.
Hi,
ANy help with start and end time validation check please ?
The validation logic doesnt re runs when datetime picker control's value is changed
Could you provide soem insights on the similar situation but with datetime picker control?
when i chaneg my hour/date/minute picker values, teh validation isnt rerunning.
How shoudl i make it work ?
how to fix this when it also has time say they put in the same date but the time is other way.
Stay up tp date on the latest blogs and activities in the community News & Announcements.
Mark your calendars and join us for the next Power Apps Community Call on January 20th, 8a PST
Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.
User | Count |
---|---|
203 | |
171 | |
63 | |
32 | |
31 |
User | Count |
---|---|
339 | |
270 | |
105 | |
71 | |
56 |