On Blur field text field action not working immediately

Explorer ,
Sep 06, 2022 Sep 06, 2022

Copy link to clipboard

Copied

Hey thanks for reading.

I have a text field that runs javascripts On Focus and On Blur. On Focus, the field is cleared and reset in specific ways. On Blur, if the text field is not filled, the field displays the default value.

The problem:

When the user Blurs (when user clicks off the field) nothing happens, the field stays blank. The effect only runs if the user clicks off a second time. This 'delay' does not always happen either. Which makes me even more confused, and suggests there is a bug?

 

Any ideas how to stop this?  The problem is magnified when i have other codes that go into effect when, e.g., a field is left blank.

 

//On focus://

event.target.strokeColor = ["RGB",0.863,0.863,0.863]; event.target.borderStyle = border.u; if (event.target.value==event.target.defaultValue) { event.target.value = ""; event.target.textColor = color.black; }

 

//on blur://

if (event.target.value=="") { event.target.value = event.target.defaultValue; event.target.textColor = color.ltGray; }

TOPICS
JavaScript , PDF forms

Views

96

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 06, 2022 Sep 06, 2022

Copy link to clipboard

Copied

It's probably the other scripts interfere.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 06, 2022 Sep 06, 2022

Copy link to clipboard

Copied

what is the default value?

 

Your script is trying to set onBlur and onFocus actions to change the field properties of a text field object; not a widget.

 

So you need a value to aid in triggering the desired event... So,  where is  or what is that default value?

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 09, 2022 Sep 09, 2022

Copy link to clipboard

Copied

The default value is a string: "Internal". At present it stored in the Text Field Properties of the field, under Options>Default Value.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 09, 2022 Sep 09, 2022

Copy link to clipboard

Copied

To avoid such delays, The best way to change the property of a field object is with a custom format script, or in combination with a keystroke script or validation script.

 

The delay you're experiencing while using the current  onFocus/onBlur event method is because of how the data is precommited  before the trigger event; mostly during the typing activity(or copying and pasting from another source),  and how it will get fully commited after hitting the tab key, enter or clicking outside of that field, for example.

 

In the context of what you're trying to achieve, the triggering of the input data will behave similarily if you were employing a Keystroke event script; in both instances, the script requires that user enters data into that texfield, then the data is precommited as it is typed into the field, and finally it must be validated (or captured) before the triggering event fully commits that data.

 

Here's a good article, published by ACP Thom Parker, that explains better how that works:

 

 

With that in mind, a script that will work well to change the appearance properties of a button widget, radio buttons, checkboxes, listboxes or dropdown menu objects,   will not behave in the same way for a textfiled object, specially if you have other scripts running custom calculating script that depend on what data is entered on that textfield.

 

If you want to enforce field property changes in real time and with no delays,  modify your current script to a custom Format script as shown below in my example.

 

This worked for me :

 

 

 

event.target.strokeColor = ["RGB",0.863,0.863,0.863]; 
event.target.borderStyle = 
border.u; 

if(event.value !== "" && (event.value !== "Internal")) {

event.target.textColor = color.black;

 } else {

event.value = event.target.defaultValue; 
event.target.textColor = color.ltGray; 

}

 

 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 10, 2022 Sep 10, 2022

Copy link to clipboard

Copied

Huge thanks for this. I must digest this.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 11, 2022 Sep 11, 2022

Copy link to clipboard

Copied

LATEST

You're welcome.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines