I think your button solution isn’t that bad: create a ‘default’ button that sets the association, and a ‘primary’ button that removes it.
You can use conditional visibility to make sure only one of them is visible: use an expression to check on the specific association, show one when it’s empty, and one when it isn’t.
I didn’t notice that you only have 1 association: favoritenumbers_person.
That means your data model needs some extra attributes or associations, which hold information on this relationship. You can choose for associations: next to the existing one, there needs to be an association per button/selectable value. On the button, select ‘based on expression’ in the ‘visibility’ submenu and check on the specific association to be empty or not. When a person clicks the button, create/delete the object and set/empty the association.
Alternatively, you can create booleans on the person object which you set on a button click triggered microflow, and base conditional visibility on this. This isn’t the prettiest solution though.
Finally, using only the existing association you have, you could choose to add a ‘checked’ boolean to the ‘favouriteNumber’ entity. Make sure to generate (if necessary) all objects (one for each selectable value) before/when a user enters the screen, and use the ‘Number’ attribute as button caption. the button checks/unchecks the ‘checked’ boolean, which you can use to determine which button to show. Use a template grid for displaying the objects, or a listview that shows items horizontally (use the forum to see how to achieve this, is can be done pretty easy).
Which option to choose depends on how flexible you want the solution to be: the third option could even be generated/based on a run-time configurable list of selectable options, opposed to the first solution which would require a change to your data model every time an option needs to be added.
Hi Wieke, thanks for your answer.
would you then create the association & the new object via a microflow? And how would you delete the object and the association again?
If I understand you correctly, you would place both the default and the primary button in the parent data view "Person" and make their visibility dependent on the existence of the association to the child object.
Can you explain in more detail how I make the visibility of the buttons dependent on the existence of the association? And what expression do I use for that?