cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ramanan89
Helper III
Helper III

If Validation and Error Message Issue

Hi,

I am trying to validate the below code, not getting required output. Here I am validating either the user has uploaded in attachment field or has link to the attachment. But it only submits form if both are filled,

 

If(
            CountRows(DataCardValue12.Attachments) < 1 Or IsBlank(DataCardValue2.Text),
            Notify(
                "File not uploaded or link to the file missing!",
                NotificationType.Error,
                4000
            ),
            SubmitForm(FormNewRequest)
        )

 

 Link Field here is a hyperlink field - which is not a mandatory field.

 

Another issue, I am facing is that when I enter text (not a link) in hyperlink field. It doesn't submit the form, but no error is displayed. Not sure why. I checked the properties of error message text, all are valid. Strange behaviour, any idea what might be the issue.

 

Thanks.

16 REPLIES 16

@ramanan89 

Also, if you want the message only during edit, you can alter it to this:

    Parent.DisplayMode=DisplayMode.Edit &&
    CountRows(DataCardValue12.Attachments) = 0 &&
    !IsBlank(DataCardValue2.Text) &&
    IsMatch(DataCardValue2.Text, "(([\w]+:)?//)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,63}(:[\d]+)?(/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?")
_____________________________________________________________________________________
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.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

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

Hi, 
Unable to make it work, no idea what is the issue. Attaching the screenshots and codes used,

 

Screenshot 2020-07-16 at 10.01.59 PM.png

 

ErrorMessage2 Visible Property code

Parent.DisplayMode=DisplayMode.Edit &&
    CountRows(DataCardValue12.Attachments) = 0 &&
    !IsBlank(DataCardValue2.Text) &&
    IsMatch(DataCardValue2.Text, "(([\w]+:)?//)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,63}(:[\d]+)?(/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?")

 

SubmitButton OnSelect code

Set(
    varMyRequestValue,
    LookUp(
        MyRequest,
        DLDate = Text(
            DateValue2.SelectedDate,
            "[$-en-GB]dd/mm/yyyy"
        ),
        TotalSlides
    )
);
If(
    !IsBlank(varMyRequestValue) And varMyRequestValue < Value(DataCardValue6.Text),
    Notify(
        "No Availability",
        NotificationType.Error,
        4000
    ),
    If(
        DateValue2.SelectedDate < Today() Or Weekday(DateValue2.SelectedDate) = 1 Or Weekday(DateValue2.SelectedDate) = 7 Or DateValue2.SelectedDate > varDate Or DateTimeValue(DateValue2.SelectedDate & " " & HourValue2.Selected.Value & ":" & MinuteValue2.Selected.Value) < Now(),
        Notify(
            "Please select a date within 3 business days",
            NotificationType.Error,
            4000
        ),
        If(
            CountRows(DataCardValue12.Attachments) = 0 && (IsBlank(DataCardValue2.Text) || ErrorMessage2.Visible),
            Notify(
                "File not uploaded or link to the file missing!",
                NotificationType.Error,
                4000
            ),
            SubmitForm(FormNewRequest)
        )
    )
)

 

Thanks

@ramanan89 

I do see that I left out a ! in my formula.  I was copying and pasting from my test for you and my logic was set just a little different.

Change to:

Parent.DisplayMode=DisplayMode.Edit &&
    CountRows(DataCardValue12.Attachments) = 0 &&
    !IsBlank(DataCardValue2.Text) &&
    !IsMatch(DataCardValue2.Text, "(([\w]+:)?//)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,63}(:[\d]+)?(/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?")
_____________________________________________________________________________________
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.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

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

Yay... 😄 Its working finally... Thank you so much 🙂

Even I did one mistake, forgot to mention the "Link Invalid" in text property after I inserted the textbook again.

 

One more help, Link Invalid message is not displayed when we attach a file and also try to add a invalid link. The error message is blank and form cannot be submitted.

 

Thanks 🙂

@ramanan89 

So you want that to display even if there are attachments...Then change to this:

Parent.DisplayMode=DisplayMode.Edit &&
    !IsBlank(DataCardValue2.Text) &&
    !IsMatch(DataCardValue2.Text, "(([\w]+:)?//)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,63}(:[\d]+)?(/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?")

 

You can also consider setting the Visible property of the DataCard with Link in it:

CountRows(DataCardValue12.Attachments) = 0

The datacard will show if there are no attachments, but be gone if they attach.

 

Just a suggestion as well.

_____________________________________________________________________________________
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.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

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

Thank you so much 🙂

Thanks for the suggestion also, I am not sure if I will be using it. B'cos sometimes user might attach and also share the link. So will retain as it is for now. 🙂

@ramanan89 

Sounds good.

_____________________________________________________________________________________
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.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

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

Helpful resources

Announcements
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 (1,268)