UI Toggle Button Value Data Binding

I have a quick question about the toggle button in the UI builder. It doesn’t appear to have a “Value Logic” handler like other input buttons do. I also saw in another support thread that it’s default state won’t be bound anywhere automatically.

Does that mean that when I used a toggle I need to set up an On Mount event that will assign a property to the default value, then use the On Change handler to modify that property when the toggle is changed?

Since the toggle essentially takes a true/false state I am surprised that I can’t directly bind this to a value like with other inputs. Maybe I’m missing something obvious though.

Thanks for the help!

1 Like

Hello @James_Hereford ,
Thank you for contacting us, we are always happy to help.
Such a handler exists, it is called “Checked State Logic”

You can also set a default value in the tab (USER INTERFACE) which will have a lower priority compared to the handler and date binding.

Regards,
Sergey


Thanks Sergey. I do see how I am able to control the toggle state using that handler. I just want to confirm though - is there no way to ‘read’ the current state of the UI toggle (including the starting state) and save that into a variable?

It seems like in your example I would have needed to create the property ‘isChecked’ in Page Data before being able to use it in the Checked State Logic handler. Is that correct?

Thanks!

Hi @James_Hereford

yes, specifying initial data in a DataModel will work
another approach is using the “Checking” option in the UI Settings and data-binding for the “Checked State Logic”, if it’s enabled in the UI Settings and it has data-binding it sets the value on the first render

Regards,
Vlad

Ahh, that makes sense. Thanks so much for clarifying!

1 Like

Hey Vlad or another team member, I just want to double check. If a checkbox or toggle field is not enabled in the UI builder by default, the value of “false” will NOT be automatically bound to a data property matching the data binding, correct?

Therefore, if I need to a toggle or checkbox to default to a value of false then I need to create that property somewhere in my code and set it to false when the property first loads. If not, there is a risk that the user will not click it at all and the value will remain “null” instead of being set to “false”.

Is that a correct understanding?

yes, that’s correct

1 Like