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

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!

Accepted Solutions (0)

Answers (9)

Answers (9)

ab35711410

09-07-2020

Bruce,

 

My apologies for the delayed response.  I have tried it on two computers with the same result.  Unless there is another script that may work without turning on/off the Highlight Existing Fields feature, it would appear that I will not be able to achieve the desired result for my form.   

 

~AB

_Bruce_Robertson

MVP

08-07-2020

The runtimeHighLight property is one of the users application preferences.  It is the same as if you went into Edit ... Preferences ... Forms and change the highlight color options there.

 

Maybe you have one of the other settings there getting in the way.  Can you try a different computer and see if the same things happens?

ab35711410

07-07-2020

Bruce,

 

Yes sorry, it was meant to be a lower case "F."  I tried the script in the docReady event as suggested and it did not turn off the Highlight Existing Fields option.  Just to make sure none of my form parameters/settings were preventing the script from working correctly, I entered the script on your provided test from without success. 

 

I did have a glimmer of hope when I saved it as a static form and then back to a dynamic form.  For some reason that turned off the highlighting during that odd moment.  Of course, it also turned off highlighting for all of my adobe forms.  Once I chose the option to highlight the fields again, it of course stopped working.  It seems odd that changing the Highlight Existing Fields option on one form affects all of my PDFs.  Is there any way around this or do you have any other suggestions?  Thank you.

_Bruce_Robertson

MVP

06-07-2020

Hi,

 

your code to turn off highlighting should work, as long as the "F" of false is in lowercase, if that just some sort of auto correct in this forum? And, I would put it in the docReady event.

 

There is more about the field highlighting, with a sample, in Niall's blog, https://experienceleaguecommunities.adobe.com/t5/adobe-livecycle/ct-p/adobe-livecycle-community

 

Bruce

ab35711410

06-07-2020

Bruce,

 

The script works when I turn off the highlight fields option on my form.  Unfortunately, turning it off also turns it off for all of my forms in Adobe.  Is there any way to customize this setting for the form itself to where it does not affect my overarching Adobe settings?  I tried the following script in the Form Ready event without success.  Any suggestions would be greatly appreciated.  Thank you.

 

app.runtimeHighLight = False

 

~AB

ab35711410

06-07-2020

Bruce,

 

The script works perfectly as long as I click to highlight the fields first.  For some reason, my form does not have the option to highlight the fields at the top of the form.  Is there any way to enter a script in the Initialize event to automatically highlight the fields?  I have searched and tried a few different scripts in various events to achieve this, but without success.  I would upload my form, but I am building it on my company's isolated network.  I greatly appreciate all of your help.  

 

~AB

_Bruce_Robertson

MVP

03-07-2020

Hi,

 

I guess there is something my code does not allow for in your form, are the fields in a repeating block, or are the field names duplicated?

 

My test form for the code is;

https://sites.google.com/site/livecycledesignercookbooks/home/ab35711410.pdf?attredirects=0&d=1

 

Can you share your form, just upload to whatever site (google docs, dropbox, etc) and post a link in this thread.

 

Bruce

ab35711410

01-07-2020

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_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!