Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

Making a field Inactive/active depending on user input

Avatar

Former Community Member
Is there any way possible to make a field inactive (user cannot enter data)...and make it active at run time depending on user action.



I have a form with one drop down list(with choices yes & No) and two text boxes..



if the user selects "yes" from the drop down list, then both the fields become mandatory...else they are optional...My problem is if the user tabs out of first text field without entering..an error message is displayed...and the tab goes to next text field..user cannot enter anything there as there is an error message from previous textfield..so if I try to tab out of Text field2..second error msg is displayed as it is mandatory too..now I am unable to get out of this loop....I have to terminate the application in order to stop it...can anyone please help??
24 Replies

Avatar

Former Community Member
When you say that "both fields
become mandatory" when "yes" is selected from the drop down list, do you mean you're using script to set the two fields to mandatory when "yes" is selected? (I'm just trying to better understand your scenario.)



Stefan

Adobe Systems

Avatar

Former Community Member
Yes i am using script to make the text fields mandatory..as it is an If..then situation..

Avatar

Former Community Member
Finally got it to work....



when form is first loaded, made the Textfield2.access="readOnly";



On exit event of textfield1, made textfield2.access="open";

Avatar

Former Community Member
Great! I'm glad the solution was simple in the end. Sorry I wasn't much help this time.



Stefan

Adobe Systems

Avatar

Former Community Member
I am still having a little problem though...The field is open now...but I am not able to set focus on that field...



In the tab order, I have specified it right after textfield1, also in script when I make the access open, i do xfa.host.setfocus("Textfield2"); but this doesnt seem to work,....

Avatar

Former Community Member
Are you sure you don't have a typo in your script? Is the second text field named "Text
field2" or "Text
Field2"?



Stefan

Adobe Systems.

Avatar

Former Community Member
You may also want to try setting focus to the field
before setting its access property to "open" -- especially if setting it to "open" causes the mandatory error message box to appear.



Stefan

Adobe Systems

Avatar

Former Community Member
I've checked thoroughly for all Typ-O's and infact tried giving the full path and everything..same thing works if i donot change the access of the field...then the setFocus method works great....



My form is a simple print form....How can i make sure that user fills in TextField2 before he prints out the form....provided drop down list says YES...

Avatar

Former Community Member
I tried to set focus before changing access property to open...doesn't work either...

Avatar

Former Community Member
The reason why the xfa.host.setFocus("TextField2") call isn't working is because TextField2 doesn't actually get enabled until control returns from TextField1's Exit event whereas the call to set focus to TextField2 is executed immediately -- at which point TextField2 is still read-only, causing the set focus call to fail.



I'm trying to think of way you could get around this timing issue.



Stefan

Adobe Systems

Avatar

Former Community Member
Is there a sleep method like Visual Basic or anything matching that..where in we could specify a time interval...that should solve this immediate execution problem...

Avatar

Former Community Member
That's a great idea and in fact, there is a timer that you can set using the Acrobat Scripting Model.



In the Exit event on TextField1, try using this JavaScript script:



TextField2.access = "open";

app.setTimeOut("this.getField('form1[0].#subform[0].TextField2[0]').setFocus();", 1);


Here, the code in quotes is the code you want to execute after X number of milliseconds (the second argument of the app.setTimeOut method).



When executing, the context (
this) is now the Acrobat Document Object and therefore, you must use the getField method to access objects on the form. You must also specify all form object occurrences (as you can see above).



Stefan

Adobe Systems

Avatar

Former Community Member
In response to your question about preventing the form from being printed if TextField2, for example, isn't filled, I'm afraid there isn't a definitive way of doing this via XFA. The only thing you could do is notify the user that they didn't fill-in a mandatory field (using the prePrint event on the top-level form object) but you wouldn't be able to cancel the print action. You would have to trust that the user would cancel the Print Dialog in Acrobat, fill-in the mandatory field and try printing again.



In order to disable the Print function in Acrobat, you would have to write an Acrobat Script which would disable the Print button but it would do so for
all documents, not just your form. This obviously wouldn't be a good solution. And even then, this wouldn't prevent the user from using the "Ctrl + P" print command...



Stefan

Adobe Systems

Avatar

Former Community Member
This code is working with alerts, message boxes everything, except setting the focus onto textfield2...



Logically the code should work great but somehow it is not....

Avatar

Former Community Member
Just to double-check: You've renamed the words in the script I suggested to match your object names as well as set the script's language to JavaScript?



Is there a message box that appears when exiting TextField1? This might be interferring with the setFocus solution...



Stefan

Adobe Systems

Avatar

Former Community Member
Yes, i did rename the subform name and object name to match my form...also there is no message box being displayed..but I did try to display a message box, instead of setting the focus onto the field..the Message box gets displayed...But if i try to set the focus it doesn't...

Avatar

Former Community Member
Are you only testing this via the Preview tab (to preview the form in Acrobat)? I'm asking because I've seen the tab order get messed-up when testing a form in the Preview tab. Tabbing order has an effect on the "app.setTimeOut" solution in that if Acrobat thinks that there's no field to go to after tabbing-out of TextField1 (because TextField2 is initially read-only), it won't execute TextField1's Exit event when the tab key is pressed while in TextField1, which means the app.setTimeOut code won't even get executed.



Try showing a message box in TextField1's Exit event as follows (in JavaScript):



xfa.host.messageBox("test");


If the message box doesn't show, then you've got this tab order problem. Try saving the form as an Acrobat 7.0.5 Dynamic PDF and test it in Acrobat itself.



There's also the case where you would have only two fields on your form, TextField1 and TextField2 with TextField2 set as read-only initially. In this case, Acrobat wouldn't let you tab out of TextField1 (and wouldn't execute TextField1's Exit event script) because it thinks TextField2 is read-only and can't be tabbed into but I don't think this is your case (I believe you at least have one other field, the "yes/no" drop down list, on your form).



If you still can't get focus to go to TextField2 in stand-alone Acrobat, we'll have to figure something else out.



Let me know what you find out.



Stefan

Adobe Systems

Avatar

Former Community Member
I am using acrobat to check the code..i used the message box code you gave..it works fine...so that means the exit event is working...

One thing that I did notice is that if the textfield2 is read-only..when i tab out of Textfield1, focus is lost..it doesnot get set on any other field either(My form has more than 20 fields)



But if I make the textfield2 "invisible" during form load and make it "visible" on exit event of textfield1, focus is set on the textfield3 which is right after textfield2 in tab order...



does that mean anything??I am not sure....



Also it looks like when I tab out of textfield1, it takes a few seconds for textfield2 to get active...and in the meantime focus gets shifted to textfield3...I noticed this when I made textfield2 invisible/visible instead of open/readOnly....So I guess using timer to delay is only making it slower and hence not helping...let me know if you do not understand what i mean...



Thanks for trying so much and helping on this issue..i really appreciate your input

Avatar

Former Community Member
Marleen L wrote:

> I am using acrobat to check the code..i used the message box code you gave..it works fine...so that means the exit event is working...

> One thing that I did notice is that if the textfield2 is read-only..when i tab out of Textfield1, focus is lost..it doesnot get set on any other field either(My form has more than 20 fields)

>

> But if I make the textfield2 "invisible" during form load and make it "visible" on exit event of textfield1, focus is set on the textfield3 which is right after textfield2 in tab order...

>

> does that mean anything??I am not sure....

>

> Also it looks like when I tab out of textfield1, it takes a few seconds for textfield2 to get active...and in the meantime focus gets shifted to textfield3...I noticed this when I made textfield2 invisible/visible instead of open/readOnly....So I guess using timer to delay is only making it slower and hence not helping...let me know if you do not understand what i mean...

>

> Thanks for trying so much and helping on this issue..i really appreciate your input



Marleen,

In order to use setFocus(), it requires a full SOM expression for the

field. Here is an example:

xfa.host.setFocus(this.parent.textfield2.somExpression);



See if this helps.



Also, I have noticed that setting something to "visible" or "invisible"

always results in a bit of a delay as you mentioned. Your timer is not

causing this problem.



Justin Klei

Cardinal Solutions Group

Avatar

Former Community Member
You're welcome.



I'm sure we'll figure this one out but I'm starting to think it would really help if I could have a look at your form. Would you be able to post it somewhere temporary where I could download it?



I might be able to see something that's not raising a flag via this thread...



Stefan

Adobe Systems