Updating Records Based on Button State

Hellooo all!

Will put my solution here if I find the solution before some expert provides me the solution. So that more people can benefit.

I have a few buttons for the user to tap for choosing interests. I’ve placed the state which allows specific types ‘valid’, ‘invalid’.

When user taps on the buttons to choose interests, how then do I update record with the buttons which are in valid state (chosen)?

I reckon I need to tag each interest radio button to a page variable eg state_frisbee, preview value ‘frisbee’. And in the logic flow, once it’s tapped, state_frisbee turns ‘valid’.
Currently, Im stuck at this stage. How then do I add frisbee to the page variable called ‘interests’ and then update the record whenever another interest is chosen eg climbing without deleting the previous interests chosen?

Has it got to do anything with CONCAT, WITH_UNIQUE_ITEM, WITHOUT_ITEM (when invalid)?

Also, am I able to limit their interests to a maximum number?

Will try to figure out on my own simultaneously as well, but greatly appreciate your advice if you’ve been there done that. Cheers!

There’s a page variable set for interests. pageVars.interests

There’s also a page variable set for state of each interest. eg state_soccer.

State_soccer has 2 allowed values: invalid, valid. Initial value is invalid. Upon component tap, it becomes valid. If it’s valid and tapped, it becomes invalid. This triggers the change of UI.

Also, when it is valid, I have set value of pageVars. interests (in logic flow) to be

IF(pageVars.state_soccer === ‘valid’, WITH_UNIQUE_ITEM(pageVars.interests, 'soccer, '), ,WITHOUT_ITEM(pageVars.interests, 'soccer, '))

[For the above logic, it is then completed with Update record value of pageVars.interests (type: list), debugger captures the update but nothing shows up on backend.

I realized why nothing is showing. My data at backend(using backendless) is a text type, it can be changed to a string type. But I don’t think it makes any difference. Bcos pageVars.interests needs to be a text type to be compatible.
However, WITH_UNIQUE_ITEM and WITHOUT_ITEM’s first param needs to be a list, so I guess that’s where the problem lies. If pageVars.interests is a text type, and is the first param for the 2 functions mentioned, it clashes with the need for the 1st param to be a list type and the pageVars.interests doesn’t capture any changes as seen in the debugger.

Then i tried this for trial and error…

IF(pageVars.state_soccer === ‘valid’, IF(!IS_IN_ARRAY(pageVars.interests, ‘soccer’), pageVars.interests + ’ soccer, ', pageVars.interests), WITHOUT_ITEM(pageVars.interests, ‘soccer,’))

It’s possible to add soccer into the backend but there’s a string ‘null’ at the front, and tapping it again on mobile preview to remove it will remove other options too, I thought the WITHOUT_ITEM function will only remove ‘soccer’.

Any help will be greatly appreciated. @Cecilia @Mevi @Harri_Sarsa @Mari Thanks!

I’m not sure I understand the structure of your data – you say that your data is text type (which is same as String type). The data for interests. So… Is it that you have a data resource like “Users” of which “interests” is only one field, which is text type, or something else? Either way, it sounds like it would serve you better if this interests field was a List (Array) of Objects. This way, it would be easier to display the data and edit it. The structure can be very simple, the object can just have one field (like name, maybe an id as well) and that’s everything required.

If you’re handling a String (text), it becomes complicated. Basically, you’ll have to split it into a list of Object in Composer (into a page variable for example) using e.g. SPLIT and MAP formulas. And then you’ll have to make it back into a String with JOIN or something similar.