## Which form event to use on form-open to change text object caption?

28-11-2016

Hello, I have a checkbox that when selected will change the caption of a text object and two text fields, and when deselected will revert back to their default caption. When the form is reopened, I want the text object's caption as well as the two text fields' caption to be set according to the checkbox being selected or not.

I can do it for the two text fields using their 'form:ready' event. But the text object has no scripting events to use. So I'm assuming the text object's caption needs to be changed using an event at the form level. I believe it is the form's 'docReady' event but I can't make it work. I've tried other form events and no one works. So I don't know if it is that I'm not using the correct form event or the correct scripting, or a combination of the two.

Here's the scripting the checkbox uses to change the captions when selected/deselected (this works fine): form1.Page1.DGSiteInfo.Row2.Table1.Row1.blnAdditionNMSystem::change - (JavaScript, client)

if (this.rawValue == 1) //the box is checked

{

form1.Page1.Specs.Row3.Table1.Row2.lblInstalledKW.rawValue = "Added generator capacity (kW)"; //change text object caption           form1.Page1.Specs.Row7.Table1.Row1.numInverterQty.caption.value.resolveNode("#text").value = "Number of added inverters:"; //change text field caption           form1.Page1.Specs.Row7.Table1.Row1.numTotalInverterKW.caption.value.resolveNode("#text").value = "Total added inverter capacity:" //change text field caption

}

else

{

form1.Page1.Specs.Row3.Table1.Row2.lblInstalledKW.rawValue = "Installed generator capacity (kW)"; //change text object caption           form1.Page1.Specs.Row7.Table1.Row1.numInverterQty.caption.value.resolveNode("#text").value = "Number of inverters:"; //change text field caption           form1.Page1.Specs.Row7.Table1.Row1.numTotalInverterKW.caption.value.resolveNode("#text").value = "Total inverter capacity:"; //change text field caption

}

Here's the scripting one of the text fields uses when the form opens, the other text field follows the same scripting (this also works fine): form1.Page1.Specs.Row7.Table1.Row1.numInverterQty::ready:form - (JavaScript, client)

//will ensure the label is properly set based on the controlling field when the form is opened

if (DGSiteInfo.Row2.Table1.Row1.blnAdditionNMSystem.rawValue == 1) //if controlling field value is checked

{

form1.Page1.Specs.Row7.Table1.Row1.numInverterQty.caption.value.resolveNode("#text").value = "Number of added inverters:"; //change field caption

}

//else, the field automatically uses its default caption

Here's the scripting I've tried to use in the forms 'docReady' event (and other form events) to change the text object's caption when the form opens (this doesn't work):

//will ensure the label is properly set based on the controlling field when the form is opened

if (DGSiteInfo.Row2.Table1.Row1.blnAdditionNMSystem.rawValue == 1) //if controlling field value is checked

{

form1.Page1.Specs.Row3.Table1.Row2.lblInstalledKW.rawValue = "Added generator capacity (kW)"; //change text object caption

}

//else, the field automatically uses its default caption

#### Accepted Solutions (1)

MVP

29-11-2016

Hi,

These are the sort of changes that are preserved when you have "Preserve scripting changes to form when saved" set to automatic under File ... Form Properties ... Run-time.

But there are times when you don't want this, in which case you should be able to add the JavaScript code;

this.execEvent("change");

in the initialise event of the blnAdditionNMSystem checkbox, this will perform the same logic as if the checkbox was clicked on opening.

Regards

Bruce