← servoy magazine

[Tip] Checkbox fun

  • Tips

by Harjo Kompagnie
www.directict.nl

Here is great tip to select only one item with checkboxes out of different (related) records like you can do that with a radio button in one record!

In this case the key feature of a Radio button is that you can only choose one!

Now I want to use the same feature to select a primary record out of more (related) records. For instance: I have 3 addresses in 3 different records and I want one addres shown/to become the primary address.

One way to do this is checking a checkbox! hugh? Yes a checkbox...

And here's how to do this:

Create an integer column in your adresses table named primary and place a checkbox in tableview or listview.

Create the below method and attach it to the 'onDataChange' property of your form:

//update entire foundset
var fsUpdater = databaseManager.getFoundSetUpdater(foundset);
fsUpdater.setColumn('primary',0); // first blank them all
fsUpdater.performUpdate();
primary = 1; // set the current record
controller.saveData();

voilah!

Harjo