Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Conditional Formatting using events

Avatar

Former Community Member
Hi,

I am having trouble with setting strikethrough formatting on text fields based on the value of a check box field.

I have two read only text fields and a checkbox. If the box is checked I want field 1 to be formatted with strikethough and field 2 to be plain, and vice versa if it is unchecked.

I have written a 'Calculate' event for each of the text fields that contains a conditional statement. ie

Field1::calculate

if (checkboxField.rawValue == "checked") then

textField1.font.lineThrough = "1"

else



textField1.font.lineThrough = "0"

endif

$.rawValue = $.rawValue



Field2::calculate

if (checkboxField.rawValue == "checked") then

textField2.font.lineThrough = "0"

else



textField2.font.lineThrough = "1"

endif

$.rawValue = $.rawValue



I then wrote an onChange event for the checkbox that says

textField1.execCalculate()

textField2.execCalculate()



Unfortunately the formatting of the field(s) do not change predictably. Does anybody have any ideas on how to do this?



Thanks



Andrew.
2 Replies

Avatar

Former Community Member
Hi Andrew,



You can try this javascript in the change event of the checkbox:



function setStrikeThrough (fldName, strikeSetting)

{

var strikeFld = xfa.resolveNode(fldName);

strikeFld.font.lineThrough = strikeSetting

}



if (checkboxField.rawValue == "checked")

{

setStrikeThrough ("textField1", "1");

setStrikeThrough ("textField2", "0");

}



else

{

setStrikeThrough ("textField1", "0");

setStrikeThrough ("textField2", "1");

}



Regards,



Chris Fourie

www.intelliform.co.za

Avatar

Former Community Member
Thanks for the reply Chris,



I should have mentioned that I had already tried changing the formatting directly from the change event, and also using the initialize events of the two text fields with the execInitialize() method. The execCalculate was the closest to working - if I didn't include the $.rawValue = $.rawValue at the bottom of the script then the strikethrough worked, it just changed the values of the fields to "0" and "1" as well as the formatting changes.



I have sinced worked out that all of these options will work if I save the form as a Dynamic form rather than a Static one.



Apprechiate your time.



Regards



Andrew.