cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Ms-PowerRanger2
Helper I
Helper I

How to validate dates before submit form record?

I have the following in the "Required" field of a data card.  I don't want the form to submit if either of the conditions are true.  (See comments in code).  The only time this works and won't allow you to save the record is for the 2nd condition, but doesn't work for the 1st one.  I need insight on how to stop the "Saving" of a record in a form if there are errors such as this.  Are there other ways to validate the data.

 

Or(
If(
And(
Not IsBlank(CurrentDateValue.SelectedDate),
Value(CurrentDateValue.SelectedDate) < Value(PreviousDateValue.SelectedDate)
),
true, false)           //true if the current date has a value and it is < previous steps date
,If(
And(
Not IsBlank(NextDateValue.SelectedDate),
IsBlank(CurrentDateValue.SelectedDate)

),     //true if filling in next date prior to this date
true,false)
)

3 ACCEPTED SOLUTIONS

Accepted Solutions
RandyHayes
Super User
Super User

@Ms-PowerRanger2 

The best way to go about this is to disable the submit capability to the user until the form is valid.

 

Set your DisplayMode property on your submit button to:

If(
    IsBlank(CurrentDateValue.SelectedDate) ||
    IsBlank(NextDateValue.SelectedDate) ||
    CurrentDateValue.SelectedDate < PreviousDateValue.SelectedDate,
    Disabled,
    Edit
)

If you use the Required property on the datacard for this instead, then you will need to do it for each datacard with those date controls and you would then need to check the IsValid property of the form before SubmitForm.

 

I hope this is helpful for you.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

Ms-PowerRanger2
Helper I
Helper I

"I found out that I could Disable submit button if validation errors.  Since a similar condition exist for the Error Message associated with the data card and that works.  I ended up doing something like this

 

= If(  Not IsBlank(errormsg1.text)||
Not IsBlank(errormsg2.text)
,
Disabled,
Edit)"

View solution in original post

RandyHayes
Super User
Super User

@Ms-PowerRanger2 

Well again, if you put formulas in the Required properties of the datacards, then the only thing you need in your Submit button DisplayMode is:

   If(yourForm.IsValid, Edit, Disabled)

 

So which are you going to utilize, the Required properties or just put it in the DisplayMode (all of it - not the IsValid) property a formula to validate?

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

4 REPLIES 4
RandyHayes
Super User
Super User

@Ms-PowerRanger2 

The best way to go about this is to disable the submit capability to the user until the form is valid.

 

Set your DisplayMode property on your submit button to:

If(
    IsBlank(CurrentDateValue.SelectedDate) ||
    IsBlank(NextDateValue.SelectedDate) ||
    CurrentDateValue.SelectedDate < PreviousDateValue.SelectedDate,
    Disabled,
    Edit
)

If you use the Required property on the datacard for this instead, then you will need to do it for each datacard with those date controls and you would then need to check the IsValid property of the form before SubmitForm.

 

I hope this is helpful for you.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

Ms-PowerRanger2
Helper I
Helper I

"I found out that I could Disable submit button if validation errors.  Since a similar condition exist for the Error Message associated with the data card and that works.  I ended up doing something like this

 

= If(  Not IsBlank(errormsg1.text)||
Not IsBlank(errormsg2.text)
,
Disabled,
Edit)"

View solution in original post

RandyHayes
Super User
Super User

@Ms-PowerRanger2 

Well again, if you put formulas in the Required properties of the datacards, then the only thing you need in your Submit button DisplayMode is:

   If(yourForm.IsValid, Edit, Disabled)

 

So which are you going to utilize, the Required properties or just put it in the DisplayMode (all of it - not the IsValid) property a formula to validate?

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

Hi Randy

 

I also have this issue on the MS forms date selection issue. Would you please let me know where to set this to my forms for fix the date select problem, thanks. 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (2,172)