check/uncheck a checkbox based on status

Hi All

I have a list of activities and status stored in a table.
I want to display the list of activities with checkboxes which must be checked or unchecked based on status (1 or 0).
I have created a valuelist and attached it to a field with displayType check. All the activities are listed as checkbox. How do i check/uncheck based on the status column. ie if status is 1, the activity must be checked.

Thanks
arao

You don’t have to attach a valuelist when using a checkbox. As soon as the dataprovider has a value 1, the box is checked.
Be aware: as soon as you uncheck a checkbox, the value is set to 0.

Good morning Arao.

If your activities list is static the best way is using a check box for each one, in the other hand if your activities list is dynamic (you have it in a table that the users manages), something like users and groups the users belongs to, you should do it this way:

This is what you will get:
[attachment=0]Pic1.jpg[/attachment]

  1. In my case I have created a valueList with the Groups table, returning the groupID. Also a relation between the table Users and UsersGroups on the userID.
    UsersGroups holds the groups a user belongs to.
  2. The form has a form variable “usersGroups” type String:
/**
 * @type String
 *
 * @properties={typeid:35,uuid:"B09E7518-D379-4082-BFE8-C7EFBB9D5585",variableType:12}
 */
var userGroups = '';
  1. I have placed a check field on the form with this properties:
    3.1) displayType: CHECK
    3.2) dataProvider: userGroups
    3.3) valueList: vlGroups
  2. The onRecordSelection event of the form has the following code: What it does is load the groups for that user as an array in the userGroups form variable.
    This code is not inside the event, is a separated function but I call it from the onRecordSelecion event.
if (utils.hasRecords(foundset.users_to_usersgroups)) {
	userGroups = databaseManager.convertToDataSet(foundset.users_to_usersgroups, ['groupid']).getColumnAsArray(1).join('\n');
}else{
	usersGroups='';
}
  1. The onDataChange event of the field usersGroups has the following code:
function usersGroups_onDataChange(oldIDs, newIDs, event) {
	if(!frmIsAdding){
		var fs = users_to_usersgroups.duplicateFoundSet();
	
		var idColumnName = 'groupid';
		var nombreColumnName = 'groupname';
		var id;
	
		oldIDs = (oldIDs) ? new String(oldIDs).split('\n') : [];
		oldIDs.sort();
	
		newIDs = (newIDs) ? new String(newIDs).split('\n') : [];
		newIDs.sort();
	
		if (newIDs.length > oldIDs.length) {
			id = newIDs[newIDs.length - 1];
			for (i in oldIDs) {
				if (oldIDs[i] != newIDs[i])
					id = newIDs[i];
			}
			if (fs.newRecord()) {
				fs[idColumnName] = id;
				databaseManager.saveData(fs.getSelectedRecord());
                                // Here some code to add the user in the group in the Servoy Security
			}
		}else {
			id = oldIDs[oldIDs.length - 1];
			for (i in newIDs) {
				if (oldIDs[i] != newIDs[i])
					id = oldIDs[i];
			}
			if (fs.find()) {
				fs[idColumnName] = id;
				if (fs.search()){
					// Here some code to delete the user from that group in the Servoy Security
					fs.deleteRecord();
				}
			}
		}
                updateUI(); // This will call the function I showed in step 4
		return true;
	}else{
		return true;
	}
}

I took this code from the Servoy samples and adapted it to my needs.

I hope this can help you

Thanks jasantana…

I wanted something similar…