Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Loop through list of required fields then highlight/set focus

Avatar

Level 3

Yet another one that should be straightforward but is giving me a headache!

I've set a validateForm.checkForm function on a button (not a submit button) where I'm sending in the form -

if

(validateForm.checkForm(xfa.form))

Within the checkForm function I'm doing the following initial steps:

function

{

    var myForm = completedForm.nameOfTopForm.nameOfSubformThatHoldsEverything;

checkForm(completedForm)

    var firstSubformName = myForm.nameOfFirstSubform;

If the firstSubformName is visible, I then check the value of the field inside it:

var

if (ddlUnderFirstSubform.rawValue == 1) // not selected

{

    // do stuff

}

Originally I was simply highlighting each required field in turn by doing:

highlightErrors(ddlUnderFirstSubform);

xfa.host.setFocus(ddlUnderFirstSubform);

This worked fine.

But then I wanted to keep a list of all the errors & highlight/setFocus to all at the same time, so:

var reqFieldsList = new String(); // set as global var

if (reqFieldsList == ""){reqFieldsList = reqFieldsList + ddlUnderFirstSubform;}

else{reqFieldsList = reqFieldsList + ',' + ddlUnderFirstSubform;}

When I've been through the whole form & try the following it doesn't work:

if

{

(reqFieldsList != "")    var reqFields = reqFieldsList.split(',');    var firstField = reqFields[0];    highlightErrors(firstField);

xfa.host.messageBox('A message', 'Title for box', 0, 0);

ddlUnderFirstSubform = firstSubformName.nameOfDropdown;

    xfa.host.setFocus(firstField);

}

app.alert on the firstField in both the original method & new list method shows that ddlUnderFirstSubform is [object XFAObject], but one method wors the other doesn't - any ideas?

Apologies for the long-winded message - by the way, I'm not using the in-built LiveCycle required unctionality but merely going through all fields that I know are mandatory.

Thanks,

1 Reply

Avatar

Level 3

It's ok - I've sorted it!

Turns out that as my reqFieldsList was a string, the objects saved in there that I was trying to reference would have been strings, hence none of the commands I set for them would work.

I have now created an array - var reqFieldsArr = new Array();

Pushed each required field object into it - reqFieldsArr.push(requiredFieldObject);

Then looped through them at the end -

if

(reqFieldsArr != null)

{

    var counter = reqFieldsArr.length;

    var firstField;

    for (var f=0; f<counter; f++)

    {

          highlightErrors(reqFieldsArr[f]);

          if (f == 0)

          {firstField

= reqFieldsArr[f];}

    }

    xfa.host.messageBox('A number of mandatory fields have not been completed. Please check through the form and complete the highlighted fields');

    xfa.host.setFocus(firstField);

    return false;

}

else

{

return true;}

Might help someone else.....