Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

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

Avatar

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

Avatar

Level 10

Hi,

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

Regards

Bruce

Avatar

Level 2

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

Avatar

Level 10

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

Avatar

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.

Avatar

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

Avatar

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?

Avatar

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!