Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.
SOLVED

Make a field required based on input in another field

Avatar

Level 1

So I have researched the forum to answer the question of how to make certain fields in a form required if a value is entered in another designated field, and not required if no value is entered in the designated field.

For example:

There is a field titled QTY_paper, and if a value is entered into QTY_paper, then the field PROGRow1 should become required.

If no value is entered into QTY_paper, then PROGRow1 is not required.

I've tried both FormCalc and Javascript, but with no results. In FormCalc I added this script as a mouseExit event on QTY_paper:

if ($.isNull == 0) then

     //Make the budget field Required
     PROGRow1.validate.nullTest = "error";
endif

and then I added this script in FormCalc to the mouseExit event on PROGRow1:

if ($.isNull == 0) then

$.validate.nullTest = "disabled"

endif

This came almost verbatim from another post on the forum, so I'm thinking I'm missing something obvious here... which isn't too odd as I'm still pretty new at adding the scripts. Please help if you can!

1 Accepted Solution

Avatar

Correct answer by
Level 10

Yeah a lot of dynamic stuff isn't supported in the static pdfs, some stuff works and a lot doesn't. That's too bad you can't rebuild the form.

While the border colour is not changing, the field may still be getting set to mandatory and so it may still function as a mandatory field.

The other alternative would be to do all the fields and scripting in Acrobat.

View solution in original post

6 Replies

Avatar

Level 10

You'd want to combine both scripts on the first field with an if/else statement. And I'd use the Exit event instead of Mouse Exit (not sure if Mouse Exit handles tabbing in and out of fields).

The first script should have worked, but with the second script you were asking if PROGRow1 was null, not QTY_paper.

FormCalc:

if ($.isNull) then

     PROGRow1.validate.nullTest = "error"

else

     PROGRow1.validate.nullTest = "disabled"

endif

Avatar

Level 1

This makes sense, and it is odd that it doesn't work with the Exit event but will work with the MouseExit and somewhat work with the change event.

As you guessed, the MouseExit doesn't highlight the field if you tab through, but will highlight if you do a mouse click. The change event will highlight the field, but only if you happen to mouse over it or tab through it... otherwise the highlighting isn't there.

The Exit event doesn't highlight at all. Am I correct in understanding that the script should be limited to the QTY_paper field and that there is no need for any script on the PROGRow1 field?

This seems pretty odd that the script works some of the time and not others.

Avatar

Level 10

It should work fine on the exit event, not sure what's happening there. Is your form saved as a dynamic form? (File>Save As>Adobe Dynamic XML Form.)

And yes, you don't need any scripting on the PROGRow1 field.

Avatar

Level 1

I should have noted that this is originally a pdf with the form fields added on later in LiveCycle 8.2. There isn't an option other than to save as a static PDF form.

Our workflow doesn't support creating the form from scratch in LiveCycle, though I know that would get better results most likely.

It has worked just fine in the past with simple commands (save as, sum, etc) and I was guessing that would mean that it would accept the conditional.

Is there any hope for this patient, or do I need to put this form out of it's misery?

Avatar

Correct answer by
Level 10

Yeah a lot of dynamic stuff isn't supported in the static pdfs, some stuff works and a lot doesn't. That's too bad you can't rebuild the form.

While the border colour is not changing, the field may still be getting set to mandatory and so it may still function as a mandatory field.

The other alternative would be to do all the fields and scripting in Acrobat.

Avatar

Level 1

Looks like I may have run up against the limits of the form. Thanks for your assist!