I have an interface where a user is able to click on several choices in a checkbox. Each selection is stored as a separate row in a data table that is linked to their user data. Adding new choices is easy as you just write a new row for that box. Removing them is a bit more tricky. Is there a standard best practice for this row addition/subtraction process?
Discussion posts and replies are publicly visible
Here is an simple example using local variables:
a!localVariables( local!checkBoxesFromDB: { a!map(id: 1, value: "ITEM_1"), a!map(id: 2, value: "ITEM_2") }, local!checkBoxValue: local!checkBoxesFromDB.value, local!checkBoxesToAdd, local!checkBoxesToRemove, { a!checkboxField( label: "Check box field", choiceLabels: { "Item 1", "Item 2", "Item 3" }, choiceValues: { "ITEM_1", "ITEM_2", "ITEM_3" }, value: local!checkBoxValue, saveInto: { local!checkBoxValue, a!save( local!checkBoxesToAdd, a!forEach( items: local!checkBoxValue, expression: a!map(id: fv!index, value: fv!item) ) ), a!save( local!checkBoxesToRemove, difference( cast( typeof({ a!map() }), local!checkBoxesFromDB ), cast( typeof({ a!map() }), local!checkBoxesToAdd ) ) ) } ) } )
gotcha, so I come up with separate lists of things to add and things to remove. Thanks
If you found my advice helpful, please consider marking the response as verified. Thanks! :)