Skip to main content
Jul 1, 2022 8:48 AM UTC
Solved

Passing which button was clicked to a service

Hello,

 

i want to build a simple calculator. For this I would want to create 10 buttons for each digit and 6 buttons for plus, minus, multiply, divide, delete, equal. 

Then a computation services that takes the label of the buttons pressed as input.

 

But here I am already stuck. I haven't found a way to pass a value for a button to a service. Logic; if button "4" was clicked, input parameter "digit" should be "4".

 

I have already tried setting a contextID and working with event routers but the problem is that the context ID should only be passed  when the button is clicked, but it will always pass.  

 

I would appreciate any help!

 

Thank you.

Jul 1, 2022 11:21 AM UTC

If you use an expression before the Event Router I believe this should work (to control when exactly the value is passed to the Event Router).

Can you please check if the example I built in attachment works? (it's not very optimized...)

3 replies

Jul 1, 2022 11:21 AM UTC

If you use an expression before the Event Router I believe this should work (to control when exactly the value is passed to the Event Router).

Can you please check if the example I built in attachment works? (it's not very optimized...)

Jul 4, 2022 9:37 AM UTC

Thank you so much!

So the only way would be to create more than 16 Expressions (one for each button)?

 

Jul 4, 2022 11:51 AM UTC

Hi again, 

I think the expression router and event combo, even if it is a bit of work to write an expression for each button, could work. Thank you!

 

However can you think of a way to implement the logic, that unless a user clicks on one of the operator buttons, the numbers pressed should be appended?

So if i first click 1, then 2, it should be number 12. 

 

I am also a bit clueless where to store the numbers and the operators that should be passed to the calculation service. In an non-persistent InfoTable thing property? 

 

Thank you!