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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to change another ...
Power Apps
Answered

How to change another elements property inside OnChange

(0) ShareShare
ReportReport
Posted on by 23

I want to execute this piece of code :

Button_submit.DisplayMode = If(Len(tx_summary.Text) > 50, DisplayMode.Disabled, DisplayMode.Edit)

it gives me the following errors :

Incompatible types for comparison, These types can't be compared: Error, text

Invalid use of '.'

I would like to either disable or enable a button based on whether the user has entered too many or just enough characters. Please help where applicable

Categories:
  • kelseytran Profile Picture
    292 on at

    Hi @dadekore ,

     

    Try this code which checks that tx_summary.Text isn't blank and is the right type of value:

     

     

    Button_submit.DisplayMode = If(
     IsBlank(tx_summary.Text) || !IsText(tx_summary.Text),
     DisplayMode.Disabled,
     If(
     Len(tx_summary.Text) > 50,
     DisplayMode.Disabled,
     DisplayMode.Edit //
     )
    )

     

    ------------------------------------------------------------------------------------------------------------------------------

     

    If I answered your question, please accept my post as a solution and if you liked my response, please give it a thumbs up.

     

    Thanks!

     

  • LaurensM Profile Picture
    12,516 Moderator on at

    Hi @dadekore,

     

    Your code looks ok. Please note that should you use the Modern text input or a Text Input within Power Apps for Teams / Custom Page, you will need .Value as suffix instead of .Text:

    If(
     //tx_summary.Value (see cases above)
     Len(tx_summary.Text) > 50, 
     DisplayMode.Disabled, 
     DisplayMode.Edit
    )

     

    Additionally, make sure the control name is written correctly.

     

    If this solves your question, would you be so kind as to accept it as a solution.

    Thanks!

  • dadekore Profile Picture
    23 on at

    Hi , thanks for the contribution. How would I assign the DisplayMode value to the Submit buttons DisplayMode property

  • LaurensM Profile Picture
    12,516 Moderator on at

    @dadekore 

     

    The If() statement should be written within the DisplayMode property of the Submit Button.

    LaurensM_0-1708975741996.png

     

    I hope this helps!

  • dadekore Profile Picture
    23 on at

    Thank you! It's still not working as expected despite the fact that I just republished my PowerApps Form but I'm assuming it takes a few minutes for the changes to take place? As you can imagine my vision is 

    1. This form is not submittable should the user not fill in all the fields 2. The user must provide an adequate summary and description before submitting. 

  • LaurensM Profile Picture
    12,516 Moderator on at

    @dadekore 

     

    Please note that with the current code you will disable the button once the summary is longer than 50 characters - otherwise it is enabled. Since you also want to disable the text input when the field is blank, you may also want to use the !IsBlank function (is not blank).

     

    In case you want to check multiple fields, we will have to add extra conditions. In the example below I will name the description field 'tx_description' - please adjust accordingly:

     

    //Enable the button if both summary and description are not empty AND both contain less than or equal to 50 characters
    If(
     //tx_summary.Value, tx_description.Value (see cases in previous comment)
     !Isblank(tx_summary.Text) && Len(tx_summary.Text) <= 50 && 
     !Isblank(tx_description.Text) && Len(tx_description.Text) <= 50 , 
     DisplayMode.Edit, 
     DisplayMode.Disabled
    )

     

    Should both fields need to be between a certain amount of characters, you could replace the !IsBlank with another Len function:

    //Enable the button if both fields contain between 10 and 50 characters
    If(
     //tx_summary.Value, tx_description.Value (see cases in previous comment)
     Len(tx_summary.Text) >= 10 && Len(tx_summary.Text) <= 50 && 
     Len(tx_description.Text) >= 10 && Len(tx_description.Text) <= 50 , 
     DisplayMode.Edit, 
     DisplayMode.Disabled
    )

    With this approach you may want to provide some visual guidance (e.g. label stating the expected text length) on your screen as to not confuse the user.

     

    I hope this helps!

  • dadekore Profile Picture
    23 on at

    Actually yes. My apologies. My code was already doing that. The changes are integrated seamlessly but seem to have no effect. Please see the following code :

    If(
     !IsBlank(Dropdown_10134.Selected) && !IsBlank(Dropdown_10107.Selected) && !IsBlank(Dropdown_10100.SelectedText) && !IsBlank(Dropdown_10099.SelectedText) && !IsBlank(10098) && !IsBlank(10096) && !IsBlank(Dropdown_10095.SelectedText) && !IsBlank(Dropdown_10094.SelectedText) && !IsBlank(Dropdown_10061.SelectedText) && !IsBlank(dropdown_10037.SelectedText) && !IsBlank(DatePicker1.SelectedDate) && !IsBlank(var_currentuser.userPrincipalName) && !IsBlank(tx_description.Text) && Len(tx_summary.Text) < 50 && Len(tx_description.Text) < 32700,
     DisplayMode.Edit,
     DisplayMode.Disabled
    )
  • LaurensM Profile Picture
    12,516 Moderator on at

    Thank you for the additional info @dadekore.

     

    To better understand the issue - would it be possible to further explain what unexpected behaviour is occurring with the given code?

     

    Additionally, please note that the part below will always return true. The code evaluates whether those numbers are not empty:

    !IsBlank(10098) && !IsBlank(10096)

     

    Thanks!

  • dadekore Profile Picture
    23 on at

    Thank you for your continued patience with me on this matter @LaurensM 

    I've corrected the code and removed the two conditions you mentioned.

    There is no unexpected behavior but rather the expected behavior is absent. When I publish the changes, I test the boundaries of the summary and description text boxes and the submit button appears and stays clickable . I've had someone suggest using a Notify() but I'm not sure that will prevent the data from being sent will it? I'm sending the data off using JIRA plugins/APIs

    If(
     !IsBlank(Dropdown_10134.Selected) && !IsBlank(Dropdown_10107.Selected) && !IsBlank(Dropdown_10100.SelectedText) && !IsBlank(Dropdown_10099.SelectedText) && !IsBlank(Dropdown_10095.SelectedText) && !IsBlank(Dropdown_10094.SelectedText) && !IsBlank(Dropdown_10061.SelectedText) && !IsBlank(dropdown_10037.SelectedText) && !IsBlank(DatePicker1.SelectedDate) && !IsBlank(var_currentuser.userPrincipalName) && !IsBlank(tx_description.Text) && Len(tx_summary.Text) < 50 && Len(tx_description.Text) < 32700,
     DisplayMode.Edit,
     DisplayMode.Disabled
    )

     

  • LaurensM Profile Picture
    12,516 Moderator on at

    @dadekore,

     

    I unfortunately am not able to recreate the issue - the displaymode changes as soon as I surpass the character limit. Troubleshooting-wise you could add labels to your screen to provide more information:

    //Label 1
    Len(tx_summary.Text)
    
    //Label 2
    Len(tx_description.Text)

     

    Can you confirm that your If statement is written in the Button's DisplayMode property (see previous screenshot). You may also want to turn off DelayOutput (DelayOutput property set to false) on the respective text input controls (description & summary) because this could result in a slight delay of the Len calculations.

     

    Since you mentioned 'text boxes' - please note that the Text Box (Power Apps for Teams or Custom Page) or Text Input Canvas (modern controls) text value is referenced via the suffix .Value instead of .Text. e.g. Len(tx_summary.Value)

     

    I hope this helps!

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 395 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 260 Most Valuable Professional

Last 30 days Overall leaderboard