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.

1 ACCEPTED SOLUTION

Accepted Solutions

@ramanan89 

Rather than throw up error notices and all kind of other confusing things, you might consider a simple approach of indicating to the user that the hyperlink is invalid.

 

Consider changing the Error Message label in your datacard with the following Text property "Link is Invalid"

Then change your Visible property to the following:

    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})*)?")

(I wish PowerApps had a predefined pattern for URLs!)  So the pattern is a little length, but it will match valid URLS.

 

Anyway, the story here is that if there are no attachments and the user has typed into the Hyperlink entry, the error message will show if it is not valid.

 

You can then add to your original formula the following condition:

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

 

Or better yet, just not let them submit!  Change the DisplayMode property on your Submit button to:

If(
    CountRows(DataCardValue12.Attachments) = 0 && 
    (IsBlank(DataCardValue2.Text) || ErrorMessage2.Visible),
    Disabled,
    Edit
 )

 

So many choices!!

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

View solution in original post

16 REPLIES 16
RandyHayes
Super User III
Super User III

@ramanan89 

 

I believe you want to change your condition to AND (&&) if the attachments are 0 AND the datcardvalue is blank, then nothing was submitted, thus give notice.

 

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

 

I hope this helps solve both issues for you.

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

Yes. This works. I got confused with AND and OR. 😛

Thanks.

 

Any idea on the error message, if its not a hyperlink entered in the textbox it is not showing any error but the form cannot be submitted until I enter valid link. I have not made any changes to the list field, has only inserted the field. Atleast if I can throw a notification error, that helps.

@ramanan89 

Have you defined the column as a text column or a hyperlink column?  If it a hyperlink column, then it must be valid to save.

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

It is a Hyperlink field and it only takes Hyperlink. The problem is that it doesn't throw up any error if we type some text instead of hyperlink in the field, but anyways it won't allow to save/submit the form. So user is unaware of what is happening. At least if I can throw a notification error saying "Not a valid link", that helps.

 

Thanks

@ramanan89 

Rather than throw up error notices and all kind of other confusing things, you might consider a simple approach of indicating to the user that the hyperlink is invalid.

 

Consider changing the Error Message label in your datacard with the following Text property "Link is Invalid"

Then change your Visible property to the following:

    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})*)?")

(I wish PowerApps had a predefined pattern for URLs!)  So the pattern is a little length, but it will match valid URLS.

 

Anyway, the story here is that if there are no attachments and the user has typed into the Hyperlink entry, the error message will show if it is not valid.

 

You can then add to your original formula the following condition:

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

 

Or better yet, just not let them submit!  Change the DisplayMode property on your Submit button to:

If(
    CountRows(DataCardValue12.Attachments) = 0 && 
    (IsBlank(DataCardValue2.Text) || ErrorMessage2.Visible),
    Disabled,
    Edit
 )

 

So many choices!!

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

View solution in original post

Hey, thank you so much for your efforts. 

Still the link validation is not working as expected, it is not displaying any error message. I have tried inserting another label for error messages, but no luck. The submit disable button is working, again it gets enabled if I type some text in hyperlink field. Even if its enabled it will not pass the invalid text to list.

A suggestion, changing the hyperlink to text field will help? I am gonna try that. Will update you soon.

@ramanan89 

Yes, definitely changing the column to a text column will resolve that.

But if you need hyperlink validation, what I sent should work fine.  In fact, I tested it out here completely before sending to you.

 

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

Not sure. What is the issue.

One doubt, I should replace the Visible Property of error message1 to this code right ?

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})*)?")

 

Replacing the existing code

Parent.DisplayMode=DisplayMode.Edit

 

@ramanan89 

Yes, that would be what to replace.  It should be on the ErrorMessage label in your datacard that corresponds to the hyperlink column.

Since you mention DataCardValue2 in your information, I would assume you would be looking for ErrorMessage2 to do this.

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

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

Top Solution Authors
Top Kudoed Authors
Users online (31,114)