Change Textfield (with default text) color when user changes the content

Avatar

Avatar

ab35711410

Avatar

ab35711410

ab35711410

29-06-2020

Hello,

 

I am developing a form and would like to highlight a textfield to remind the user to enter required information.  This textfield will include a paragraph (set with default text) with certain portions that require the user to manually enter information while keeping the rest of the content.  I would like the textfield to highlight in yellow upon opening the form and then turn off the highlighting or turn the content background to white when the user modifies the default text. 

 

I have tried everything that I can think of to get this working (e.g., Action Builder, setting the background color, etc.) to no avail.  I am pretty sure this will require a custom Javascript, but I am very new to scripting and not sure how to go about this.  Any help would be greatly appreciated.  Thank you!

View Entire Topic

Avatar

Avatar

_Bruce_Robertson

MVP

Avatar

_Bruce_Robertson

MVP

_Bruce_Robertson
MVP

30-06-2020

Hi,

 

Try this code in the layout.ready event

 

 form1.#subform[0].TextField1::ready:layout - (JavaScript, client)
var som = this.somExpression.replace(/\[[0-9]*\]$/, "").
                             replace(/\[[0-9]*\]\./g, ".").
                             replace(/xfa\.form/, "$template").
                             replace(/#subform\./, "");
var f = xfa.resolveNode(som);
if (this.isNull || f.value.text.value == this.rawValue) { // is field empty or the default value
	this.ui.oneOfChild.border.fill.color.value = "255,255,153";
} else {
	if (this.ui.oneOfChild.border.isPropertySpecified("fill")) {
		this.ui.oneOfChild.border.nodes.remove(this.ui.oneOfChild.border.fill);
	}
}

 

You could also try having separate fields for the portion of the default text that can change and then using floating fields display the values in a paragraph, depending on the amount of text and the number of them that could be easier for the form filler.

 

Regards

Bruce

Bruce, Thank you very much for your response. When I insert the script into the layout.ready event, the following occurs:

- Field does not highlighted upon opening the form

- Field highlights yellow when the user clicks on the text field to modify the default content

- If the user modifies the default content, then the text field will not highlight again upon entering/exiting the field

- If the user does not modify the default content, the highlight will turn off upon exiting the field, but will turn back on when the field is reentered.

 

Ideally what I am looking for is the following condition:

- Text field highlights yellow upon opening the form

- When the default content is modified, then the highlighting is turned off

- If the user enters the field, but fails to modify the default content, the field will continue to be highlighted yellow.

 

Thank you very much for your recommendation of using floating fields. However, that option would not work well with my form. Any additional insight you may have would be greatly appreciated. Again, thank you for your response.

Bruce, Thank you very much for your response. When I insert the script into the layout.ready event, the following occurs:

- Field does not highlighted upon opening the form - Field highlights yellow when the user clicks on the text field to modify the default content

- If the user modifies the default content, then the text field will not highlight again upon entering/exiting the field

- If the user does not modify the default content, the highlight will turn off upon exiting the field, but will turn back on when the field is reentered.

 

Ideally what I am looking for is the following condition:

- Text field highlights yellow upon opening the form

- When the default content is modified, then the highlighting is turned off

- If the user enters the field, but fails to modify the default content, the field will continue to be highlighted yellow.

 

Thank you very much for your recommendation of using floating fields. However, that option would not work well with my form. Any additional insight you may have would be greatly appreciated. Again, thank you for your response.

Bruce, please see my reply as an answer to my original question. For some reason the comment section does not allow for proper formatting and runs everything together. Thank you!