Skip to main content

Notifications

Community site session details

Community site session details

Session Id : wowhYYPSJ+Lm2rwyJ6Ne+L
Power Apps - Building Power Apps
Answered

Disable "Submit" button until "Subject" field is populated, and EITHER text box or choice field is populated.

Like (0) ShareShare
ReportReport
Posted on 1 Aug 2021 05:59:57 by

 

I have a form that has three fields: a text field for the "Subject", a text field for "Emails", and a combo-box for "Internal Users"

 

jharville_2-1627796793962.png

 

 

My goal: If the Subject is populated AND either of the two other fields ("Emails" or "Internal Users") are populated, I want the "Book" button to be enabled and clickable to submit the form. If this condition isn't met, I want the "Book" button to be disabled. So if the "Subject" field isn't populated, but one of the two other fields is populated, the "Book" button should not be active.

 

My current code (in the DisplayMode of the "Book" button) currently enables the button if one of the two fields ("Emails" or "Internal Users") is populated:

 

 

If(TextInput2.BorderColor=Red&&(CountRows(ComboBox1.SelectedItems)=Blank()||CountRows(ComboBox1.SelectedItems)=0),DisplayMode.Disabled,IsBlank(TextInput2.Text)&&(CountRows(ComboBox1.SelectedItems)=Blank()||CountRows(ComboBox1.SelectedItems)=0),Disabled,!IsBlank(TextInput2.Text)||(CountRows(ComboBox1.SelectedItems)=Blank()||CountRows(ComboBox1.SelectedItems)=0),Edit)

 

 

.. but I want to add an extra piece of code that requires the "Subject" to be populated, and then looks to the current condition of my code I attached above (see if one of the "Emails" or "Internal Users" fields are populated to enable the "Book" button). 

 

(Background of my code: My "Emails" text box checks to see if the email address entered is in the correct format. If it is not in the correct format, the border of the box turns red and our boolean variable, 'Label33' is assigned "False". If it is in the correct format, 'Label33' is assigned "True" and the border of the box turns blue        ...        The conditional assignment of "True" or "False" on that "Label33" is already functional. But if the text box is populated with an incorrectly formatted email ('Label33' is "False"), I don't want the "Book" button to be clickable)

 

Would anybody be able to provide help in adding in that extra condition?

 

Thank you so much,

 

Justin

  • v-albai-msft Profile Picture
    on 13 Aug 2021 at 08:47:33
    Re: Disable "Submit" button until "Subject" field is populated, and EITHER text box or choice field is populated.

    Hi @jharville ,

    Since you have solved your issue, I would close this thread so that other community members who stuck with the same question can directly see your solution.

    Best regards,

    Allen

  • Pstork1 Profile Picture
    66,015 Most Valuable Professional on 03 Aug 2021 at 01:06:05
    Re: Disable "Submit" button until "Subject" field is populated, and EITHER text box or choice field is populated.

    That is not what happens in my sample.  I'm not sure how your code is different from what I supplied, but something isn't in the right place or with the right name.  The code you modified below is far more complex than it needs to be.  The following is with my code and you can see that the button is only live if a Subject line and one of the other controls is populated.

    image.png

    image.png

     

    image.png

    image.png

  • Verified answer
    jharville Profile Picture
    on 03 Aug 2021 at 00:25:56
    Re: Disable "Submit" button until "Subject" field is populated, and EITHER text box or choice field is populated.

    @Pstork1 

     

    I actually modified my existing code and got it to work. 

     

    If(
     IsBlank(TextSubject.Text) || TextInput2.BorderColor = Red && (CountRows(ComboBox1.SelectedItems) = Blank() || CountRows(ComboBox1.SelectedItems) = 0),
     DisplayMode.Disabled,
     IsBlank(TextSubject.Text) || IsBlank(TextInput2.Text) && (CountRows(ComboBox1.SelectedItems) = Blank() || CountRows(ComboBox1.SelectedItems) = 0),
     Disabled,
     !IsBlank(TextInput2.Text) || (CountRows(ComboBox1.SelectedItems) = Blank() || CountRows(ComboBox1.SelectedItems) = 0),
     Edit,
     !IsBlank(TextSubject.Text) || !IsBlank(TextInput2.Text) || (CountRows(ComboBox1.SelectedItems) = Blank() || CountRows(ComboBox1.SelectedItems) = 0),
     Edit
    )

     

    Thank you so much for your help though, I did learn something new and I really appreciate it! 🙂

  • jharville Profile Picture
    on 02 Aug 2021 at 23:59:34
    Re: Disable "Submit" button until "Subject" field is populated, and EITHER text box or choice field is populated.

    @Pstork1 

     

    I think I found the issue with the code. When you only populate the 'Emails" and nothing else, the "Book" button is not enabled ... which is good.

     

    jharville_0-1627948578415.png

     

    And when you add in populating the "Subject" text input, the "Book" button is enabled ... which is also good!

     

    jharville_1-1627948642411.png

     

    But here's the issue. When you take out the 'Emails' text input, and leave the Subject ... the "Book" button is still enabled, when it should be disabled.

     

    jharville_2-1627948715700.png

     

    What would we have to add to our existing code in the DisplayMode to take into account that change of removing the population of a field and having the "Book" button reflect that change?

     

     

     

  • Pstork1 Profile Picture
    66,015 Most Valuable Professional on 02 Aug 2021 at 22:42:56
    Re: Disable "Submit" button until "Subject" field is populated, and EITHER text box or choice field is populated.

    If its just the hint text and not the text or default it should work fine.  See the screenshot below.

    image.png

  • jharville Profile Picture
    on 02 Aug 2021 at 22:24:23
    Re: Disable "Submit" button until "Subject" field is populated, and EITHER text box or choice field is populated.

    @Pstork1 

     

    If I understand correctly, would I not be able to have any Hint Text if I want your method to work? 

     

    jharville_0-1627944130761.png

     

  • Pstork1 Profile Picture
    66,015 Most Valuable Professional on 01 Aug 2021 at 15:17:32
    Re: Disable "Submit" button until "Subject" field is populated, and EITHER text box or choice field is populated.

    Double check to make sure that the subject text field is actually empty and does not contain the prompt you are displaying in that box.  I tested it in a small app and it works as you requested.  If either the subject box or (either the email or combobox are not filled in) the button will be disabled.  Something about your setup is not showing the Subject box as blank.

     

    For your code you don't combine it with your code.  It is a complete replacement for the Displaymode property of the button.

  • jharville Profile Picture
    on 01 Aug 2021 at 15:12:50
    Re: Disable "Submit" button until "Subject" field is populated, and EITHER text box or choice field is populated.

    @Pstork1 

     

    Thank you for the reply. How would I combine that piece of code with the existing code that I have?

     

    My current code works to enable the "Book" button if either the "Emails" or "Internal Users" is populated, but doesn't have a condition regarding the "Subject" text input. I need to make sure the "Subject" is populated first and foremost, and then check to see if either of the "Emails" or "Internal Users" is populated to enable the "Book" button.

     

    I tested your code with just itself (took out my code), and it didn't achieve the desired function:

    jharville_0-1627830657920.png

    ^^Subject is empty, but one of the two fields ("Emails" or "Internal Users") is populated. But since "Subject" is empty, the "Book" button shouldn't be active.

     

    jharville_0-1627830731208.png

    ^^Subject is empty, but one of the two fields ("Emails" or "Internal Users") is populated. But since "Subject" is empty, the "Book" button shouldn't be active.

     

  • Pstork1 Profile Picture
    66,015 Most Valuable Professional on 01 Aug 2021 at 13:36:35
    Re: Disable "Submit" button until "Subject" field is populated, and EITHER text box or choice field is populated.

    This code in Displaymode should do what you want. Just adjust the control names to match yours.

    If(IsBlank(txtSubject.Text) || (IsBlank(txtEmail.Text) && IsBlank(ComboBox1.SelectedItems)),DisplayMode.Disabled, DisplayMode.Edit)

     

     

  • jharville Profile Picture
    on 01 Aug 2021 at 06:02:45
    Re: Disable "Submit" button until "Subject" field is populated, and EITHER text box or choice field is populated.

    @v-xiaochen-msft 

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,700 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,015 Most Valuable Professional

Leaderboard