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 / Setting a variable ins...
Power Apps
Unanswered

Setting a variable inside component in the OnChange event of a text input

(0) ShareShare
ReportReport
Posted on by 13

Hi. I have a component that has a text input and a text label. This text label is used to indicate the error in the text label. I created an attached custom behavior property that is linked to the onchange of the text input. This property returns a record composed of ErrorText and ErrorVisibility. Also in the onchange of the text input I am setting a variable inside the component to use the output to set the visibility and text of the text label.

Set(varErrorInfo,TextInputWithError.TextLabelOnChange());

 

I use this varErrorInfo to set the visibility and text of the text label.

 

So in my application I am putting some logic to check if the text of the component is blank. I am exposing the text as an output property in the component.

 

Here is my logic for checking if its blank:

 

If(IsBlank(Self.Text), {ErrorVisibility: true, ErrorText: "Email cannot be blank!"}, {ErrorVisibility: false, ErrorText: ""})

 

 

So this works fine but when I try to add logic to check if its duplicate like this, it does not work.

 

If(
 IsBlank(Self.Text),
 {
 ErrorVisibility: true,
 ErrorText: "Email cannot be blank!"
 };
 Notify("Email cannot be blank");
 ,
 If(
 IsBlank(
 LookUp(
 Reviewers,
 Email = Self.Text
 )
 ),
 {
 ErrorVisibility: false,
 ErrorText: ""
 },
 {
 ErrorVisibility: true,
 ErrorText: "Email already exists"
 };
 Notify("Email duplicate");
 )
);

 

 

I am confused to what the issue is. I added Notify events to make sure my logic is correct and I am getting the correct Notifications but my component doesnt seem to be getting the output properly.

Categories:
I have the same question (0)
  • v-jefferni Profile Picture
    Microsoft Employee on at

    Hi @melsawy9 ,

     

    There are several mistakes inside your formula, please try below instead:

    If(
     IsBlank(Self.Text),
     {
     ErrorVisibility: true,
     ErrorText: "Email cannot be blank!"
     }
     ,
     If(
     IsBlank(
     LookUp(
     Reviewers,
     Email = Self.Text
     )
     ),
     {
     ErrorVisibility: false,
     ErrorText: ""
     },
     {
     ErrorVisibility: true,
     ErrorText: "Email already exists"
     }
     )
    );

     

    To send notification, the function Notify requires to be inside a behavior property. So, you can set OnChange of the Text input box to be as follows:

    If(
     IsBlank(Self.Text),
     Notify("Email cannot be blank")
     ,
     If(
     !IsBlank(
     LookUp(
     Reviewers,
     Email = Self.Text
     )
     ),
     Notify("Email duplicate");
     )
    );

     

    Best regards,

  • melsawy9 Profile Picture
    13 on at

    Hi Jeff, The notifies are working fine. The issue is that my component is not getting or setting the return values of the record (includes ErrorVisibility and ErrorText) properly. I think any variable set inside a component is global to all instances of a component. Can you verify this is not the case?

  • v-jefferni Profile Picture
    Microsoft Employee on at

    Hi @melsawy9 ,

     

    Please check below thread and you can find the answer:

    Solved: Function Set () in Components - Power Platform Community (microsoft.com)

     

    Below is the doc for your reference:

    Canvas component overview (contains video) - Power Apps | Microsoft Learn

     

    Best regards,

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 541

#2
WarrenBelz Profile Picture

WarrenBelz 434 Most Valuable Professional

#3
Valantis Profile Picture

Valantis 289

Last 30 days Overall leaderboard