cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sscarcella
Level 8

Start and end date validation

How do I make sure the user enters an end date that is greater than or equal to the start date, not before?

1 ACCEPTED SOLUTION

Accepted Solutions
PowerApps Staff CarlosFigueira
PowerApps Staff

Re: Start and end date validation

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:

ForumPost000.PNG

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:

ForumPost001.PNG

Hope this helps!

View solution in original post

8 REPLIES 8
PowerApps Staff CarlosFigueira
PowerApps Staff

Re: Start and end date validation

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:

ForumPost000.PNG

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:

ForumPost001.PNG

Hope this helps!

View solution in original post

sscarcella
Level 8

Re: Start and end date validation

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?

PowerApps Staff CarlosFigueira
PowerApps Staff

Re: Start and end date validation

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).

Bronson-Smith
Level: Power Up

Re: Start and end date validation

been trying to do that...but nothing working....... doing a similar thing in my project working on

IngoE
Level: Powered On

Re: Start and end date validation

Worx very well....thx a lot

Rkaur
Level: Powered On

Re: Start and end date validation

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.

Rkaur
Level: Powered On

Re: Start and end date validation

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

 

Rkaur
Level: Powered On

Re: Start and end date validation

Hi @CarlosFigueira 

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 ?

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (6,299)