Forum Academy Marketplace Showcase Pricing Features

Creating a toggle button

Hi!

I need a bit of help with an issue:

I want to create a button that displays a yes/no data value with green/red colour and when pressed, changes the value (and its own colour) to opposite. This workflow works perfectly, but somewhy it throws an issue. Any ideas?

Also, the same kind of issue is thrown for birthday field that it should be date but text is found. As much as I have looked around, it’s defined as date everywhere…

For the toggle you should look at “custom states” … So essentially holding a temporary state against the button. Then use conditional formatting to set the colour.

So on button press you use the Set State action. And the button changes colour based upon this state.

Hmm. Okay.
So I create a custom state - but that would mean several additional steps to make it control the data value of the thing, too.
What’s wrong with this formula here? It would be the easiest and most straightforward way to solve the need and it works just as needed. What’s the issue here, why doesn’t the compiler like it?

Hi Laur,

From your screenshot and the issue help window, it seems that you are trying to assign a yes/no value to a text variable. When the two match, the issue should go away.

Hi George,

Thanks for the answer.
The variable (IsEnabled) under the thing is of boolean (yes/no) type). What else could affect it?

The current cell’s text - it seems you are trying to cast text to Boolean? Try instead using a natively Boolean indicator, such as a checkbox.

Sorry, yes, didn’t see the box on the right as am on a small screen.

As George says, you set to Yes or No. And you could do this by having two actions , one where the value is already yes, the other where it is no. Unless there is some clever way to do that another way.

Hmm.
There is a Thing called Auth - to hold authentication methods.
It has a variable called IsEnabled, of yes/no value
The button derives its colour from the value, green for yes, red for no.
The objective is to make the variable value and button colour change on button click.

Right now the expression is
When Button Current Cell’s Auth is clicked:
Make changes to current cell’s Auth:
IsEnabled = Current Cell’s Auth’s IsEnabled:formatted as no/yes

Does this last part “formatted as no/yes” bring the text issue? I kind of figured this the easiest way to return reverse values to the variable - and on the app’s test version it works well.

edit:
Okay, I created two different actions for yes and no conditions and it works. But it seems like a waste of resources to have two actions where one would easily suffice. It should be possible to do it more simply. Devs…

Ahhhh, I see what you are doing. Very clever :slight_smile:

Yes, “formatted as no/yes” is used to output Yes/No in other ways/languages based on the boolean. So 0 = “non”, 1 = “oui” for example. Or True / False. Or No = Yes and Yes = No as you have done !

So what your expression says is to set the boolean IsEnabled to the text value as specified.

It is still a text, not a boolean, so that sounds like that is your problem.

Yup. I was pretty content having it done in one swing and it felt a bit unfair that the compiler started b!tching about it.
IMHO reversing a boolean should be a standard action as it’s needed all the time…

1 Like

True and clever - we’ll figure something out in the mid- future :wink:

I have often heard Developers talking about boolean fields, and how there are 3 (or maybe 4?) different values. Nil-able and Null and then my ears start bleeding :slightly_smiling:

Personally… (pure opinion) … this is a bit codey. If you have two workflows with conditions it is clear and obvious (if, I agree, long winded) but something that blurs Yes/No into binary… hmmmm, #nocode for me.

But very clever, it took a while to work out what you were doing and there was the “Ohhhhhhhhhh I seeeeee” moment.

1 Like