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

How to calculate a field based on completion of required fields?

hy9fesh
Level 2
Level 2

Is it possible to calculate a field as "Complete" or "Not Complete" based on completion of all the form's required fields?

For example, the form is is named "Form" and the subform is named "Subform." I was thinking of coding something in JavaScript, like the following:

if(Form.Subform.execValidate == false);

{

this.rawValue = "Not Complete"

}

else

this.rawValue = "Complete"

Yet, the above JavaScript doesn't seem to be working?

That said, I have a lot of required fields so I'd prefer not to list all of them. Please let me know if I'm on the right track!

7 Replies
_Bruce_Robertson
Level 10
Level 10

Hi,

Try using "if(Form.Subform.execValidate() == false);", that is with the brackets after the execValidate method call.

Regards

Bruce

hy9fesh
Level 2
Level 2

Thanks for the suggestion, but that doesn't appear to work either.

_Bruce_Robertson
Level 10
Level 10

It works for me, any chance you can post a link to your form?

hy9fesh
Level 2
Level 2

Give me a few minutes to mock a form up.

That said, I've placed the following code into the "calculate" event:

if(Form.Subform.execValidate() == false)

{

this.rawValue = "Not Complete"

}

else

this.rawValue = "Complete"

I want the field to show "Not Complete" or "Complete" based on the whether or not the required fields have been filled. It appears that I can't get this to work unless I put it on a "click" event of a button.

hy9fesh
Level 2
Level 2

Here you go @BR001. Thank you so much for looking into this. Note that the Completion Status is set at "Complete" for some reason, even though the required field has not been filled out:

form_sample.pdf - DocDroid

_Bruce_Robertson
Level 10
Level 10

I see what you mean, seems the execValidate() method call cancels the calculate event.  Maybe you can try using the validationState event, which came in with Reader 9.1.  This event fires when a field changes from valid to invalid or vice-versa (it also fires after the initialize and if the reason for being invalid changes).  So you could put a validationState event at the top of you form (using event propagation) with the following code;

if(form1.getInvalidObjects().length > 0)

{

    subform.CompletionStatus.rawValue="Not Complete"

}

else

{

    subform.CompletionStatus.rawValue="Complete"

}

Here is a version of your sample that implements this, https://sites.google.com/site/livecycledesignercookbooks/home/form_sample.br001.pdf?attredirects=0&d...

Mandatory fields are only flagged as invalid once an attempt to submit has been made, or a call to execValidate() has been made (or when a field that had a value is cleared).  So I have added an execValidate() in the docReady event and also set the form validation properties to not show any error message popups.

Do you have to support earlier versions than 9.1?

hy9fesh
Level 2
Level 2

Hi @BR001, it appears that your script works if the mandatory fields are not conditionally changing. I need something more specific. Thanks, though!