web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Power Apps Button OnSe...
Power Apps
Unanswered

Power Apps Button OnSelect

(0) ShareShare
ReportReport
Posted on by 67

Hi Members,

 

I had a requirement in Power Apps to create a Power Apps login screen. 

 

I have a SharePoint list [ACGH Login] with three columns:

  1. UserName [Title]
  2. Email
  3. Password

Hemashree_0-1712740211822.jpeg

 

Now. In my Power Apps, I have created a Login screen where users can log in using the fields Email/Username and password.
But, I was facing some small issues in my code like:

 

1 = Whenever the user provides the email/username and password and clicks on the login button, it does not even navigate to the next screen.

2 = Whenever the user provides the right username/email and wrong password and clicks on a button, it does not display an error like "Provide a valid password."

If(
 IsBlank(txt_Email.Text) && IsBlank(txt_Password.Text),
 Set(
 var_EmailErrorMsg,
 "Enter an Email Address or User Name"
 );
 Set(
 var_PasswordErrorMsg,
 "Enter a Password"
 ),
 If(
 IsBlank(txt_Email.Text),
 Set(
 var_EmailErrorMsg,
 "Enter an Email Address or User Name"
 ),
 Set(
 var_EmailErrorMsg,
 ""
 )
 );
 If(
 IsBlank(txt_Password.Text),
 Set(
 var_PasswordErrorMsg,
 "Enter a Password"
 ),
 Set(
 var_PasswordErrorMsg,
 ""
 )
 ),
 If(
 And(
 Not(IsBlank(txt_Email.Text)),
 Not(
 Or(
 IsMatch(txt_Email.Text, "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$"),
 EndsWith(txt_Email.Text, "@gmail.com")
 )
 )
 ),
 If(
 Not(IsEmpty(Filter('ACGH Login Details', Title = txt_Email.Text))),
 Set(var_EmailErrorMsg, ""),
 If(
 IsBlank(txt_Email.Text),
 Set(var_EmailErrorMsg, ""),
 Set(var_EmailErrorMsg, "Enter a valid User Name")
 )
 ),
 If(
 Not(IsEmpty(Filter('ACGH Login Details', Email = txt_Email.Text))),
 Set(var_EmailErrorMsg, ""),
 If(
 IsBlank(txt_Email.Text),
 Set(var_EmailErrorMsg, ""),
 Set(var_EmailErrorMsg, "Enter a valid Email")
 )
 )
 ),
 If(
 IsEmpty(
 Filter(
 'ACGH Login Details',
 (Email = txt_Email.Text || Title = txt_Email.Text) && Password = txt_Password.Text
 )
 ),
 If(
 Not(IsEmpty(Filter('ACGH Login Details', Or(Email = txt_Email.Text, Title = txt_Email.Text)))), // Check if email or username exists
 Set(
 var_PasswordErrorMsg,
 "Enter a valid password"
 ),
 Set(
 var_PasswordErrorMsg,
 ""
 )
 ),
 Navigate(HomeScreen)
 )
)

 

It is working fine up to the UserName/Email validation field. But only for the password validation is it facing an error. like the below code image:


error 1 login.jpg

 

 

 

 

 

 

 

 

 

 

 

Please, anyone, help me with the below scenarios:

1 = Whenever the user provides the email/username and password and clicks on the login button, it should navigate to the next screen.

2 = Whenever the user provides the right username/email and wrong password and clicks on a button, it should display an error like "Provide a valid password."

 

Can anyone please suggest how I can achieve this? Thanks in advance!

Categories:
I have the same question (0)
  • Verified answer
    LowCodeJim Profile Picture
    306 Moderator on at
    Re: Power Apps Button OnSelect

    Hi,

     

    I went through your existing code and tidied up the conditions a bit. I think the reason the navigation was not happening was due to some if statements nested incorrectly. Hopefully the below code should achieve what you are after:

     

    If(
     IsEmpty(
     Filter(
     'ACGH Login Details',
     (Email = txt_Email.Text || Title = txt_Email.Text) && Password = txt_Password.Text
     )
     ),
     If(
     Not(
     IsEmpty(
     Filter(
     'ACGH Login Details',
     Or(
     Email = txt_Email.Text,
     Title = txt_Email.Text
     )
     )
     )
     ),// Check if email or username exists
     Set(
     var_PasswordErrorMsg,
     "Enter a valid password"
     );
     Set(
     var_EmailErrorMsg,
     ""
     ),
     Set(
     var_PasswordErrorMsg,
     ""
     );
     If(
     Or(
     IsMatch(
     txt_Email.Text,
     "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$"
     ),
     EndsWith(
     txt_Email.Text,
     "@gmail.com"
     )
     ),
     Set(
     var_EmailErrorMsg,
     "Enter a valid Email"
     ),
     Set(
     var_EmailErrorMsg,
     "Enter a valid User Name"
     )
     )
     ),
     Set(
     var_EmailErrorMsg,
     ""
     );
     Set(
     var_PasswordErrorMsg,
     ""
     );
     Navigate(HomeScreen)
    )
  • HM-22080408-0 Profile Picture
    67 on at
    Re: Power Apps Button OnSelect

    Thank you @SharePointJB 
    It is working fine. Thank you.
    But I have another validation:


    Whenever the user doesn't provide anything in Email/UserName and Password. It should throw an error near both fields like
    Email/Username = "Enter your UserName or Email"
    Password = "Enter your password"


    For that, I have merged the code, like below:

    If(
     IsBlank(txt_Email.Text) && IsBlank(txt_Password.Text),
     Set(
     var_EmailErrorMsg,
     "Enter an Email Address or User Name"
     );
     Set(
     var_PasswordErrorMsg,
     "Enter a Password"
     ),///
     If(
     IsBlank(txt_Email.Text),
     Set(
     var_EmailErrorMsg,
     "Enter an Email Address or User Name"
     ),
     Set(
     var_EmailErrorMsg,
     ""
     )
     );
     If(
     IsBlank(txt_Password.Text),
     Set(
     var_PasswordErrorMsg,
     "Enter a Password"
     ),
     Set(
     var_PasswordErrorMsg,
     ""
     )
     );
    If(
     IsEmpty(
     Filter(
     'ACGH Login Details',
     (Email = txt_Email.Text || Title = txt_Email.Text) && Password = txt_Password.Text,
     Lower(Password) = Lower(txt_Password.Text)
     )
     ),
     If(
     Not(
     IsEmpty(
     Filter(
     'ACGH Login Details',
     Or(
     Email = txt_Email.Text,
     Title = txt_Email.Text
     ),
     Lower(Title) = Lower(txt_Email.Text)
     )
     )
     ),
     Set(
     var_PasswordErrorMsg,
     "Enter a valid password"
     );
     Set(
     var_EmailErrorMsg,
     ""
     ),
     Set(
     var_PasswordErrorMsg,
     ""
     );
     If(
     Or(
     IsMatch(
     txt_Email.Text,
     "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$"
     ),
     EndsWith(
     txt_Email.Text,
     "@gmail.com"
     )
     ),
     Set(
     var_EmailErrorMsg,
     "Enter a valid Email"
     ),
     Set(
     var_EmailErrorMsg,
     "Enter a valid User Name"
     )
     )
     ),
     Set(
     var_EmailErrorMsg,
     ""
     );
     Set(
     var_PasswordErrorMsg,
     ""
     );
     Navigate(HomeScreen)
    ))

    But now, I am facing an issue like:


    Whenever the user provides the correct Username/email and wrong password, the error message shows for the UserName/email field. But it should throw me an error for the password field, like "Enter a valid password."

    Please could you help me.

  • LowCodeJim Profile Picture
    306 Moderator on at
    Re: Power Apps Button OnSelect

    Ah, my apologies I forgot to mention that part. I instead moved the logic onto the button so that it was disabled until a value is entered in the txt_Email and txt_Password fields. I did this by adding the following formula to the "Display Mode" property of the button:

    If(IsBlank(txt_Email.Text) || IsBlank(txt_Password.Text),DisplayMode.Disabled,DisplayMode.Edit)

     

    You could also update the hint text property of each text input field with something like "Enter your UserName or Email" and "Enter your password"

    SharePointJB_0-1712747396132.png

     

    Hope that helps!

     

     

  • HM-22080408-0 Profile Picture
    67 on at
    Re: Power Apps Button OnSelect

    Hi @SharePointJB 

    Sorry, but, My scenario is that only like:
    Whenever the user doesn't provide anything in Email/UserName and Password. It should throw an error near both fields like:

    Email/Username = "Enter your UserName or Email"
    Password = "Enter your password"

    Please help me with full code with this scenario.


  • LowCodeJim Profile Picture
    306 Moderator on at
    Re: Power Apps Button OnSelect

    Only enabling the button when these fields have values in removes the need to have a check for blank fields. However if you did want to achieve this the following code should do the job:

     

    If(
     IsEmpty(
     Filter(
     'ACGH Login Details',
     (Email = txt_Email.Text || Title = txt_Email.Text) && Password = txt_Password.Text
     )
     ) And Not(IsBlank(txt_Email.Text) || IsBlank(txt_Password.Text)),
     If(
     Not(
     IsEmpty(
     Filter(
     'ACGH Login Details',
     Or(
     Email = txt_Email.Text,
     Title = txt_Email.Text
     )
     )
     )
     ),// Check if email or username exists
     Set(
     var_PasswordErrorMsg,
     "Enter a valid password"
     );
     Set(
     var_EmailErrorMsg,
     ""
     ),
     Set(
     var_PasswordErrorMsg,
     ""
     );
     If(
     Or(
     IsMatch(
     txt_Email.Text,
     "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$"
     ),
     EndsWith(
     txt_Email.Text,
     "@gmail.com"
     )
     ),
     Set(
     var_EmailErrorMsg,
     "Enter a valid Email"
     ),
     Set(
     var_EmailErrorMsg,
     "Enter a valid User Name"
     )
     )
     ),
     IsBlank(txt_Email.Text) || IsBlank(txt_Password.Text),
     If(
     IsBlank(txt_Email.Text),
     Set(
     var_EmailErrorMsg,
     "Enter an Email Address or User Name"
     ),
     Set(
     var_EmailErrorMsg,
     ""
     )
     );
     If(
     IsBlank(txt_Password.Text),
     Set(
     var_PasswordErrorMsg,
     "Enter a Password"
     ),
     Set(
     var_PasswordErrorMsg,
     ""
     )
     ),
     Set(
     var_EmailErrorMsg,
     ""
     );
     Set(
     var_PasswordErrorMsg,
     ""
     );
     Navigate(HomeScreen)
    )
    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

     

  • HM-22080408-0 Profile Picture
    67 on at
    Re: Power Apps Button OnSelect


    Hi @SharePointJB 

     

    Now, I am stuck with another small issue, In the SharePoint like has a email value as "Serena@gmail.com", but when I try to login with serena@gmail.com, it is logging in. So I have used the lower function, where I provided the code.
    But, it is facing the same issue, when I user lower function like:
    Whenever the user provides the correct Username/email and wrong password, the error message shows for the UserName/email field. But it should throw me an error for the password field, like "Enter a valid password."

     

  • HM-22080408-0 Profile Picture
    67 on at
    Re: Power Apps Button OnSelect

    Hi @SharePointJB 
    Now, I am stuck with another small issue, In the SharePoint like has a email value as "Serena@gmail.com", but when I try to login with serena@gmail.com, it is logging in. So I have used the lower function, where I provided the code. But, it is facing the same issue, when I user lower function like: Whenever the user provides the correct Username/email and wrong password, the error message shows for the UserName/email field. But it should throw me an error for the password field, like "Enter a valid password."

  • HM-22080408-0 Profile Picture
    67 on at
    Re: Power Apps Button OnSelect

    Now, I am stuck with another small issue, In the SharePoint like has a email value as "Serena@gmail.com", but when I try to login with serena@gmail.com, it is logging in. So I have used the lower function, where I provided the code. But, it is facing the same issue, when I user lower function like: Whenever the user provides the correct Username/email and wrong password, the error message shows for the UserName/email field. But it should throw me an error for the password field, like "Enter a valid password."

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 836 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 231 Super User 2025 Season 2

Last 30 days Overall leaderboard