cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
smerchatn
Level: Powered On

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?

 

Thanks

 

 

4 REPLIES 4
Community Support Team
Community Support Team

Re: DatePicker with Default Date and Validation on OnChange Only

Hi @smerchatn,

 

The OnVisible property of your Label should be:

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

Regards,

Mona

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.
Highlighted
smerchatn
Level: Powered On

Re: DatePicker with Default Date and Validation on OnChange Only

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

 

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

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

smerchatn
Level: Powered On

Re: DatePicker with Default Date and Validation on OnChange Only

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

evlevy
Level: Powered On

Re: DatePicker with Default Date and Validation on OnChange Only

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:

 

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

 

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

Power Apps 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

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors (Last 30 Days)
Users online (5,992)