Showing results for 
Search instead for 
Did you mean: 
Frequent Visitor

DatePicker with Default Date and Validation on OnChange Only

I have a custom SharePoint List customised through PowerApps.  I am facing two issues and wonder if someone could help here.  The StartDate has a default value (today()) but EndDate don't.  

OnStart of the FormScreen1, I have got the following varilable:


Set(vStartInvalidDate, false); Set(vEndInValidDate, false)

OnChange of the DatePicker, I have the following, to validate if selected date is in the past.


If(dpAccessStartDate.SelectedDate<Today(),Set(vStartInvalidDate, true ),Set(vStartInvalidDate, false ))

 On Visible property for the Label:

Or(vStartInvalidDate, DisplayMode = Edit)

1) When I add a new entry, the form shows the error label on the for EndDate.  How doI stop showing this error label until OnChange event fires?

2) Edit Form has entries which were valid at the time, but when I edit an item with past date, it shows the error label.  I want to validate only OnChange event rather than on start with Edit or New form? 


Is there a way to achieve this?





Community Support
Community Support

Hi @smerchatn,


The OnVisible property of your Label should be:

If(And(vStartInvalidDate=true, Form1.DisplayMode = Edit),true,false)



Community Support Team _ Mona Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-monli-msft  Thanks for a response.  I tried this still doesn't work.  I am on SharePoint Form so assumed you meant SharePointForm1 rather than Form1.


        vStartInvalidDate = true,
        SharePointForm1.DisplayMode = SharePointForm1.DisplayMode.Edit

I noticed that as soon as the Form gets visible, the value for my variable gets changed automatically to true if the selected date (in the existing item) in the edit form has past.  Something is triggering 'OnChange' event without me asking...!

@v-monli-msft, Any update on this, I need to know if this is possible or not so appreciate your help. Thanks

Frequent Visitor

There is a known issue with Datepicker in SharePoint form where OnChange is being fired on load, without the user actually changing the date. Workaround is to only perform OnChange() event if the user actively selects a date, or if the form item has not changed (i.e. we haven't navigated to a new form item).


So change DatePicker OnChange function to something like:


    (DataCardValue.SelectedDate <> SharePointForm.Current.ValueHoldingDate) || (lastFormItemID = SharePointForm.Current.ID),
    // put action here that should be performed on *real* OnChange


Helpful resources

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (3,869)