Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session

How Do I?: Link checkboxes to other fields in form

Avatar

Level 2

Please can someone kindly shed some light on how I can lock down and grey out some text fields when a checkbox gets checked by the form user.

Im sure this must be possible, but Im just not finding it in the Help.

Your assistance is much appreciated,

Stephanie.

4 Replies

Avatar

Level 10

Hi Stephanie,

You can achieve this with an if statement against the value of the checkbox 1 = on and 0 = off (default).

An example is uploaded (hopefully).

Note that in order for the fill script to work, the textfield(s) need to have a fill colour set in the design layout. You can access this from the Object / Field tab and Custom appearance.

The example locks one field. If you have more than one you would duplicate the appropriate lines within the if statement.

Also the .ui script has different calls depending on what the object is. So you would need to change "#textEdit" in the script with one of the following:

Date field =          #dateTimeEdit 
Dropdown =         #choiceList 
Checkbox =         #checkButton 
Text field =          #textEdit 
Numeric field =    #numericEdit

Good luck,

N.

Avatar

Former Community Member

The command to lock a field is FieldName.access = "readOnly". Now you have to put that code on the correct event. You can set it on the change event of the checkbox and test to see that it is checked. Something like this:

if (this.rawValue == 1) {

     // the checkbox is cheked so lock fields here

     fieldName.access = "readOnly";

} else {

     /the checkbox is unchecked so unlock fields

     fieldName.access = "";

}

Of course you woudl have a line for each field. Note that the "this" in th eif statement refers to the object that is running the script (in your case it is the checkbox).

Hope that helps

Paul

Avatar

Level 2

Firstly, thanks very much for taking the time to reply and sending the example.  It really helped a great deal.  Im not a scripting pro so I finally managed to get a little headway.  Im not sure how to make the text field to be white initially.  When opening the form, all my text fields are first grey. When I click it stays grey but loses two sides of its border, click again it goes white, click again it goes grey and uneditable.  Im not sure what I did but I have matched the code and replaced the fields relavent to my form.....Sorry if this is blantantly obvious, Im hopeing to learn this though.  See below for what I have.....Thankyou!

if

(this.rawValue ==

1)

{

Comments0.access

= "protected";

fld.value

= "238,238,238";

Comments0.caption.font.fill.color.value

= "238,238,238";

}

else

{

Comments0.access

= "open";

fld.value

= "255,255,255";

Comments0.caption.font.fill.color.value

= "0,0,0";

}

Avatar

Former Community Member

You may want to post your form so we can have a look.

Paul