user1623156
user1623156

Reputation: 125

How to disable field by unchecking a checkbox?

I have a question about how to implement this code

public void setFieldAccess()
{

if(HcmWorkerBankAccount.FullAmount == NoYes::Yes)
{

    hcmworkerbankaccount_ds.allowedit(false);
}
else
{
    hcmworkerbankaccount_ds.allowedit(true);
}
}

credit: http://axhelper.blogspot.com/2011/02/to-disable-record-in-form-by-unchecking.html

It says to create it on the form's methods and call it in the datasource's active method and field's modified method. I am assuming this is the field in the datasource, not on the form design.

My question is if this is how I call the method:

public int active()
{
int ret;
element.setFieldAccess();
ret = super();

return ret;
}


public void modified()
{

element.setFieldAccess();
super();
}

Upvotes: 2

Views: 8301

Answers (3)

Kenny Saelen
Kenny Saelen

Reputation: 894

It just happens to be so that I discovered a method in the Global class today that also does this.

public static void enableDSField(FormDataSource _datasource, fieldId _fieldId, boolean _enable)
{
    if (_datasource && _fieldId)
    {
        enableDatasourceFieldObject(_datasource.object(_fieldId), _enable);
    }
}

Upvotes: 1

Jan B. Kjeldsen
Jan B. Kjeldsen

Reputation: 18051

First off, your method is too verbose, this is the way to put it:

public void setFieldAccess()
{
    hcmworkerbankaccount_ds.object(fieldNum(HcmWorkerBankAccount,Amount)).allowEdit(!HcmWorkerBankAccount.FullAmount);
}

Also, call the method after the super() call:

public int active()
{
    int ret = super();
    element.setFieldAccess();    
    return ret;
}

Upvotes: 2

user1623156
user1623156

Reputation: 125

It wasn't working because I was overriding the modified method of the wrong field. I overrode the method on the field that was affected instead of the field that determines it's allowEdit functionality.

Also

public void setFieldAccess()
{

if(HcmWorkerBankAccount.FullAmount == NoYes::Yes)
{

hcmworkerbankaccount_ds.object(fieldNum(HcmWorkerBankAccount,Amount)).allowEdit(false);
}
else
{
hcmworkerbankaccount_ds.object(fieldNum(HcmWorkerBankAccount,Amount)).allowEdit(true);
}
}

Upvotes: 1

Related Questions