cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
damilola79
Frequent Visitor

Disable and enable button base on time and Click

I just want to ask if there is a way in which i can Disable a button after it has been clicked and enable it back the following day.

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @damilola79 ,

You are doing this to set the data

ClearCollect(
   onClickHandler,
   {
      ClickEventDate: Now(),
      User: User().Email
   }
)

This may be a bit of overkill, but I am trying to avoid potential errors

With(
   {
      wEvent:
      Lookup(
         onClickHandler,
         User=User().Email
      ).ClickEventDate
   },
   If(
      IsBlank(wEvent) 
      DisplayMode.Edit,
      If(
         DateDiff(
            wEvent,
            Now(),
            Days
         ) >= 1,
         DisplayMode.Edit,
         DisplayMode.Disabled
      )
   )
)

Note that this formula tests for a 24 hour difference. If you want just the next day, use Today() instead of Now().

 

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.

View solution in original post

9 REPLIES 9
dariobois
Resolver II
Resolver II

Hi,

 

You need to store the click event date and who clicked the button, into a database or locally on the device, then, check if that variable is older than today to shows the button as "Display.Edit"

 

For Example. Try this,

"On select" Button event:

 

 

ClearCollect(
    colEnableButton,
    {
        ClickEventDate: Now(),
        User: User().Email
    }
);
SaveData(
    colEnableButton,
    "colEnableButton"
)

 

 

"DisplayMode" Button property:

 

 

If(
    Or(
        DateDiff(
            First(colEnableButton).ClickEventDate,
            Now(),
            Days
        ) >= 1,
        IsEmpty(colEnableButton)
    ),
    DisplayMode.Edit,
    DisplayMode.Disabled
)

 

 

"OnStart" App event:

 

 

LoadData(
    colEnableButton,
    "colEnableButton",
    true
)

 

 

 

NOTE:

My example works only on mobile devices or powerapp desktop application because "SaveData" and "LoadData" functions are an Offline features not supported by browsers.

You can store the "colEnableButton" collection into a databese too, then get it by the User().email, as an "ID", to be sure that the button will be disabled to him if corresponds.

 

Regards!

Please it didnt work

 

dariobois
Resolver II
Resolver II

Hi!

Can you share us more information about the error?

damilola79
Frequent Visitor

 There is no error but it just doesnt work 

 

Set(
myLocation,
BingMaps.GetLocationByPoint(
Location.Latitude,
Location.Longitude
).name
);
ClockItFlow.Run(
User().FullName,
myLocation
);
UpdateContext({popup: true});
ClearCollect(
onClickHandler,
{
ClickEventDate: Now(),
User: User().Email
}
);
SaveData(
onClickHandler,
"onClickHandler"
)

@damilola79  Ok, so, is that your "OnSelect" button formula?

 

Share me the "DisplayMode" button property and OnStart App please.

 

Dario.

If(
Or(
DateDiff(
First(onClickHandler).ClickEventDate,
Now(),
Days
) >= 1,
IsEmpty(onClickHandler)
),
DisplayMode.Edit,
DisplayMode.Disabled
)

Hi @damilola79 ,

You are doing this to set the data

ClearCollect(
   onClickHandler,
   {
      ClickEventDate: Now(),
      User: User().Email
   }
)

This may be a bit of overkill, but I am trying to avoid potential errors

With(
   {
      wEvent:
      Lookup(
         onClickHandler,
         User=User().Email
      ).ClickEventDate
   },
   If(
      IsBlank(wEvent) 
      DisplayMode.Edit,
      If(
         DateDiff(
            wEvent,
            Now(),
            Days
         ) >= 1,
         DisplayMode.Edit,
         DisplayMode.Disabled
      )
   )
)

Note that this formula tests for a 24 hour difference. If you want just the next day, use Today() instead of Now().

 

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.

Hi @damilola79 ,

Just checking if you got the result you were looking for on this thread. Happy to help further if not.

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.

Thank You sir i tried it again today and it worked perfectly.

Once again thank you.

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (1,774)