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

Notifications

Announcements

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

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 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard