check/uncheck a checkbox based on status

Find out how to get things done with Servoy. Post how YOU get things done with Servoy

check/uncheck a checkbox based on status

Postby ashwinir » Wed Oct 12, 2011 9:26 pm

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
ashwinir
 
Posts: 2
Joined: Thu Oct 06, 2011 8:11 pm

Re: check/uncheck a checkbox based on status

Postby mboegem » Wed Oct 12, 2011 10:58 pm

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.
User avatar
mboegem
 
Posts: 1748
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam

Re: check/uncheck a checkbox based on status

Postby jasantana » Thu Oct 13, 2011 9:23 am

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:
Pic1.jpg
Result
Pic1.jpg (45.03 KiB) Viewed 4985 times


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:
Code: Select all
/**
* @type String
*
* @properties={typeid:35,uuid:"B09E7518-D379-4082-BFE8-C7EFBB9D5585",variableType:12}
*/
var userGroups = '';

3) I have placed a check field on the form with this properties:
3.1) displayType: CHECK
3.2) dataProvider: userGroups
3.3) valueList: vlGroups
4) 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.
Code: Select all
if (utils.hasRecords(foundset.users_to_usersgroups)) {
   userGroups = databaseManager.convertToDataSet(foundset.users_to_usersgroups, ['groupid']).getColumnAsArray(1).join('\n');
}else{
   usersGroups='';
}

5) The onDataChange event of the field usersGroups has the following code:
Code: Select all
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
Best regards,
Juan Antonio Santana Medina
jasantana@nephos-solutions.co.uk
Servoy MVP 2015
Servoy 6.x - Servoy 7.x - Servoy 8.x - MySQL - PostgreSQL - Visual Foxpro 9
User avatar
jasantana
 
Posts: 555
Joined: Tue Aug 10, 2010 11:40 am
Location: Leeds - West Yorkshire - United Kingdom

Re: check/uncheck a checkbox based on status

Postby ashwinir » Fri Oct 14, 2011 6:36 pm

Thanks jasantana..

I wanted something similar..
ashwinir
 
Posts: 2
Joined: Thu Oct 06, 2011 8:11 pm


Return to How To

Who is online

Users browsing this forum: No registered users and 5 guests