User should be able to select only one check box and other check box's to be disabled automatically

Dear all,

I have a employee details form.In a grid there are multiple entries with respect to Employee id.For one employee if grid details the user should be restricted to select only one check box.If he tries to select more than one check box then remaining check box to be disabled automatically.Like overall only one check box to be selected reamining to be disabled

Regards,

Sindhu

Hi Sindu,

You have to Wrtie coding in each CheckBox Modified Overried Method.

if you have three check box you shld have write modified overried method for each check Box.

Let as assume checkbox1, checkbox2, checkbox3 are avaiblibe in grid…

write the following code in Modified Override method for each Checkbox Control.

///////////////////////////////////////////

///// For CheckBox1

public boolean modified()
{
boolean ret;
;

if (CheckBox1.value()== NoYes::Yes)
{
CheckBox2.enabled(false);
CheckBox3.enabled(false);
ret = super();
}

else
{
CheckBox2.enabled(true);
CheckBox3.enabled(true);
ret = super();
}

return ret;
}

///////////////////////////////////////////////

//////////// For CheckBox2

public boolean modified()
{
boolean ret;

if (CheckBox2.value()== NoYes::Yes)
{
CheckBox1.enabled(false);
CheckBox3.enabled(false);
ret = super();
}

else
{
CheckBox1.enabled(true);
CheckBox3.enabled(true);
ret = super();
}

return ret;
}

//////////////////////////////////////////////////

////for checkBox3

public boolean modified()
{
boolean ret;

if (CheckBox3.value()== NoYes::Yes)
{
CheckBox2.enabled(false);
CheckBox1.enabled(false);
ret = super();
}

else
{
CheckBox2.enabled(true);
CheckBox1.enabled(true);
ret = super();
}

return ret;
}

////////////////////

Thanks for the response.But the check box will be dynamic.Like when user inserts a line in the GRID ,the check box also adds accordingly.So probably i need to write a loop through all the check box make all disabled and only the selectedd check box to be enabled.Please give me a sample how to loop adn in which method to be written.

Hi Sindhu,

I may be wrong , You have to write similar logic in FormDatasource initValue Override Method

public void initValue()

{

super();

if (checkBox1.value == NoYes::Yes)

{

CheckBox2.enabled(false);
CheckBox3.enabled(false);

}

else if (checkBox2.value == NoYes::Yes)

{

CheckBox1.enabled(false);
CheckBox3.enabled(false);

}

else

{

CheckBox1.enabled(false);
CheckBox2.enabled(false);

}

}

/////

Thanks for the response but the above wil not be the case.Since check box are dynamically populated.like its a check box field in grid.When the user inserts single like teh check box also adds with it.So we need to loop for the number of check box and disable all teh checkbox other than one check box which is selected by the user.there night b n number of check box.Here user is restricted to select only 1 check box and others will eb automatically disabled

What does it mean?

Hello Saadullah,

I have also the same issue regarding the check box.

I have used your code but a new problem got arises…

Suppose i have 2 check box fields say ‘C1’ & ‘C2’ and aa Id field In my form

“If i have entered an entry with C1 checked” and then if i make new entry…then my previous entry is getting locked…means i cannot uncheck the C1…

also i have a new requirement that if i check the C1 at a time and then i want to check my C2 then C1 should automatically got unchecked…

if(C1 = checked); then C2= unchecked but at the same time if i again click on C2 then it automatically get checked and C1 should get unchecked…

please try to solve my problem…

Thanks & Regards

Pranav

Hello to every one,

Can any one shall provide the solution for my problem…

Thanks in advance

Pranav

Hi Pranav,

Try this Logic

///////////////// For CheckBox1

public boolean modified()
{
boolean ret;
;

if (Check1.value()== NoYes::Yes)
{
check2.enabled(true);

ret = super();
}

else
{
check2.enabled(true);

ret = super();
}

return ret;
}

////////////////////////////////////////

//////////////For CheckBox2

public boolean modified()
{
boolean ret;

if (Check2.value()== NoYes::Yes)
{
TableName.Field1 = NoYes::No;
TableName.Field2 = NoYes::Yes;
check1.enabled(false);
ret = super();
}

else
{
check1.enabled(true);
ret = super();
}

return ret;
}

Regarding unchecking of all the checkboxes you can try the following in the modified method :

put this code at the latter part of the modified method.

if (chkbx1=noyes::no && chkbx2=noyes::no && chkbx3=noyes::no)

{

chkbx1.enabled(true);

chkbx2.enabled(true);

chkbx3.enabled(true)

}

}

Hi Saadullah,

Thanks for the code…The code is working but still after checking to C2 its getting locked means i am not able to recheck the C1 value…what to do to remove this locking…

Thanks & Regards

Pranav

//////////////For CheckBox2

public boolean modified()
{
boolean ret;

if (Check2.value()== NoYes::Yes)
{
TableName.Field1 = NoYes::No;
TableName.Field2 = NoYes::Yes;
check1.enabled(true); // if u give true it wont lock , if u give false it will lock
ret = super();
}

else
{
check1.enabled(true);
ret = super();
}

return ret;
}

Thanks…Saadullah…

Pranav

Hi,

There might be N number of check boxex in my code…not a specified number check box.It has to dynamically uncheck all the check boxes when any single check box is checked.

Hi Sindhu,

Were you able to get a resolution for this? I am facing the same issue. I have a enum type field in the table and the field is added to a grid in a form. Now I can have many rows in the grid, which effectively means many checkboxes. Now as per the requirement if I mark any 1 checkbox then all the other checkboxes should get disabled. Not sure how to achieve this. Any help on this would be really great.

Hi Abhi,

I could not get the exact solution but had a work around with the solution which is given as below

public void modifiedField(fieldId _fieldId)

{PR cpr1;

super(_fieldId);

cpr1=PR::find(this.EmplId);

Select firstonly cpr1order by cpr1.caeVoid desc where

cpr1.EmplId == this.EmplId ;

//caeVoid is the check box

if (cpr1.caeVoid == 1)

{

// info(“hi”);

this.caeVoid = 0 ;

}

}

Thanks…