Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

How to use Focus(javascript) on forms ?

Avatar

Former Community Member
Hi,



I am supposed to use javascript language to validate the fields in PDF

forms using Adobe Designer 7.0.



I would like to know how do I set the focus using javascript? As I enter eac

h field, it will validate and prompt any error message ,then it continues

for each of the remaining fields.



The clue i only have is xfa.host.setFocus(); but I have no idea how

to implement it. The focus is supposed to set on the field but it doesnt. Thank you!



PS: I'm suppose to use Adobe lifecycle designer guide yup.
5 Replies

Avatar

Former Community Member
Did you try something like that ?



xfa.host.setFocus ("xfa.form.Formular1.Textfield1");

Avatar

Former Community Member
yup I did the following which is supposed to point to the field named email

var email= Email.rawValue;

xfa.host.setFocus("email.somExpression");



Problem is after validating, it focuses on the next field.

Erm may I know what's "formular1.Textfield1"?Thx!

Avatar

Former Community Member
Hi,



I need to add a row to table dyanmically.Ho wto implement it in javascript.I dont know the javascript.Could u send me the code plz.



Thanks & regards,

Avatar

Former Community Member
----- PurchaseOrderConfirmation.PurchaseOrderConfirmation.ContactInfo.PartnerName[0]::exit - (JavaScript, client)



var partName = PartnerName.rawValue;

if (partName==null)

{

xfa.host.messageBox("Please enter partner name!");

xfa.host.setFocus("xfa.form.PurchaseOrderConfirmation.PurchaseOrderConfirmation.ContactInfo.PartnerName");

}



----- PurchaseOrderConfirmation.PurchaseOrderConfirmation.ContactInfo.Contact::exit - (JavaScript, client)



var contact=Contact.rawValue;

if( contact==null)

{

xfa.host.messageBox("Contact is compulsory!");

xfa.host.setFocus("xfa.form.PurchaseOrderConfirmation.PurchaseOrderConfirmation.ContactInfo.Contact");

}



else if(isNaN(contact))

{

xfa.host.messageBox("Contact number must be digits only!");

xfa.host.setFocus("xfa.form.PurchaseOrderConfirmation.PurchaseOrderConfirmation.ContactInfo.Contact");

}



As above,I've tried the focus you gave me. However,it keeps on prompting the partnername error msg, then check null for contact and prompt contact error msg at the same time.

I also have 2 fields with the same Name. Eg. PartnerName[0] and PartnerName[1]. How do I make sure it is pointing to the right one?



xfa.host.setFocus("xfa.form.PurchaseOrderConfirmation.PurchaseOrderConfirmation.ContactInfo.PartnerName[0]");

As follows, I used PartnerName[0] but it says missing name.



Thanks a lot!!!

Avatar

Former Community Member
i would suggest using is the key word this when you're refering to the field your in this way even if you have two fields named the same it will take the one that the cursor is in. This makes it so much easier and way less typing so you would have this



var partName = this.rawValue;

if (partName==null)

{

xfa.host.messageBox("Please enter partner name!");

xfa.host.setFocus("this");

}