Expand my Community achievements bar.

Syntax Error - setFocus to a required field

Avatar

Former Community Member
Hi,



I've read a post here about making fields required but can't get it to work. I didn't see where I was supposed to enter the script so that may be the problem.



Here is my example:

I have a field called Name that is required. I want to keep the focus on that field until something is entered.



I placed the following code under Validate:



if(form1.Page2_Subform.AddressBlock.AddressTable.Row1.Name.rawValue eq null)

xfa.host.setFocus("xfa.form1.Page2_Subform.AddressBlock.AddressTable.Row1.Name.rawValue")

endif



The error I get is:



Script failed (language is Formcalc; context is

xfa[0].form[0].form1[0].Page2_Subform[0].AddressBlack[0].AddressTable[0].Row1[0].Name[0])

script=if(form1.Page2_Subform.AddressBlock.AddressTable.Row1.Name.rawValue eq null)

xfa.host.setFocus("xfa.form1.Page2_Subform.AddressBlock.AddressTable.Row1.Name.rawValue")

endif



Error: syntax error near token 'xfa' on line 2, column 3.



I'm very good at copying and pasting scripting code but don't really understand it on my own.



Do I have this script in the right place?

How do I correct the script to work?



I was also just curious if I have to do this for every required field or is there a way to create a general script that all required fields refer to?
3 Replies

Avatar

Former Community Member
Lisa,



It looks like you need to add "then" at the end of the first line:



if (form1..Name.rawValue eq null) then



Although JavaScript doesn't require this, FormCalc does.



HTH,

Kathryn

Avatar

Former Community Member
Thanks Kathryn for responding.



I made the correction and now I don't get any errors but it still doesn't work. It just lets me tab to the next field even when the field is left blank.



I don't even get the message I entered for being a required field. The funny thing is if I open the document up in Acrobat Professional 6, all the required fields are recognized and work. Once you open up the form in anything else, including acrobat reader, the required fields are recognized because they show a red border around them when you highlight the form fields but the required message doesn't come up.



Is there another way to code a form so that focus stays on the required field until something is entered?

Avatar

Former Community Member
Hi Lisa,



I think we're in the same boat--I do a lot of copying of code (and I learn a lot that way), but there are a lot of things I don't understand. So with that caveat... :)



1) You might try putting your script on the exit event of the field.



2) When you're trying to set focus, I don't think "rawValue" needs to be included. I.e., instead of



xfa.host.setFocus("xfa.form1.Page2_Subform.AddressBlock.AddressTable.Row1.Name.rawValue")



try



xfa.host.setFocus("xfa.form1.Page2_Subform.AddressBlock.AddressTable.Row1.Name")



HTH!



Kathryn