Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Set textfield value to default value

Avatar

Level 2

Hi there.  I got a dozen textfields and datetimefields in a pdf fillable form create by livecycle designer.  All textfields and datetimefields have the  default values.  I got some javascripts to toggle checkbox to the effect that when checkbox is checked, the default value in the textfield will be cleared and let user to enter the new value; and when it is unchecked, the default value will be restored in the textfield.

default.jpg

if (this.rawValue == "1") {
  oTargetField = this.resolveNode("DateTimeField1");
   oTargetField.access = "open";
  oTargetField = this.resolveNode("TextField1");
   oTargetField.access = "open";
  this.resolveNode("TextField1").rawValue = null;
  this.resolveNode("DateTimeField1").rawValue = '';
  xfa.host.setFocus("TextField1");
}

if (this.rawValue == "0") {
this.resolveNode("TextField1").rawValue = defaultValue; }  

But, the script does not work when I uncheck the checkbox.  Any advice, please?

20 Replies

Avatar

Level 9

Hi,

In which event of the CheckBox you have put the script? If it is in click event then try it in the change event of the checkbox.

Thanks.

Bibhu.

Avatar

Level 2

Hi there.  Thanks.  In fact, the event is a "change" evant.  Any advice, please?

Avatar

Level 9

Hi,

Could you please post the form so that I can have a look ? By the way the example you have shown here is for TextField or Datefield ?

Thanks.

Bibhu.

Avatar

Former Community Member

is this the exact code that you are using to

set the textfield value to default

this.resolveNode("TextField1").rawValue = defaultValue ??

--

Chalukya

Avatar

Level 9

Hi Chalukya,

I guess the defaultValue here means the exact value he wants to show ??

Thanks.

Bibhu.

Avatar

Former Community Member

hmm ...if that is the case then pls share ur XDP/PDF....

--

Regards,

Chalukya

Avatar

Level 2

Can anyone please tell me how to upload my pdf to this forum?

Avatar

Level 2

Hi  chalukya,

I've just e-mailed the pdf form to you.  Thanks.  My prior script should be used to reset both the textfield and datetimefield to their original default values.

Avatar

Former Community Member

Hey Raymond,

u cannot use this -

this.resolveNode("TextField1").rawValue = defaultValue; //if field value = empty, then restore the default

to restore the default value of TextField1.

Assign the default value to it like ..

this.resolveNode("TextField1").rawValue = "YourDefaultValue";

defaultValue object properties is not supported in Designer ES2 support/JavaScript-equivalent in Designer ES2.

You can refer to Adobe LiveCycle Designer Help for more details.

Hope this Helps!!!!

--

Chalukya

Avatar

Level 2

Hi chalukya.  Thanks for your advice.  To repeat the default values in scripts is quite a tedius work indeed.  Anyway, thanks.  I got another problem regarding preventing checkbox from being a printable object.  I've issued a thread but still I cannot solve the problem.  I should be most grateful if you could take a look at my problem and see if there is a work around for that.  Thanks in advance.

http://forums.adobe.com/thread/840323?tstart=0

Avatar

Former Community Member

Have you tried using xfa.host.resetData("fieldName") ...this command will reset the field to its original state. You can pass multiple fields into the command separated by commas.

Paul

Avatar

Level 2

Hi there.  It seems it only works for resetting all the fields in the form.  What I want is when a checkbox1 is unchecked, the value of the textfield1 will be restored to its original default value defined in the object property.  Any modification to the effect of that?

Cheers.

Avatar

Former Community Member

If you do not pass in fieldnames to the resetData method then all fields will be reset. It is a string of names that you are passing so make sure that the string is in quotes. Tried it with one field on my machine and it works fine here.

Paul

Avatar

Level 2

Hi Paul, thanks for the prompt reply.  Here is my script and when I uncheck checkbox1, textfield1[0] and the newly entered value in textfield1[1] will be reset to their original default values instead of textfield1[0] only.  Did I miss something?

Thanks.

if (this.rawValue == "0") {
xfa.host.resetData("TextField1[0]"); }  

Avatar

Former Community Member

I think you will need the whole som expression to determine which field. If it cannot find the field then the whole form is reset. So in my case the command is xfa.host.resetData("form1.Page1.TextField1[0]")

Paul

Avatar

Level 2

Hi Paul.  Thanks.  It works after I defined the field in finer position ...like...".xfa.host.resetData("form1.#subform[0].TextField1[0]"); } ".  You are genius!!  Thanks.

Avatar

Level 2

Hi Paul,

I got a validation problem on a fillable form and want to seek your advice.  Can I e-mail my form to you for advice,please?

Avatar

Former Community Member

thanks for ur post Paul got a new think to learn on rese

tting the fields ... great !!!!!