Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events
SOLVED

Suppress blank AddressLine2 from printing

Avatar

Level 7

I'm trying the create a form that includes name and address. I'd like to include two address lines plus the City State ZIP. If AddressLine2 is blank, I'd like to avoid printing it and have the City State ZIP line move up and print in it's place.

Can anyone help me with this. I found a posting from 2008, but it didn't seem complete to this newbie.

Thanks,

MDawn

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

It can be achieved using two sub-forms, one with 2 address lines and the other with 1 address line. You can see in the image, below, the two sub-forms are defined in the hierarchy view but 'subform2' is not visible. It has the same x and y coordinates and dimensions as 'subform1'.

foo.PNG

For demonstration purposes I added a print button and the following JavaScript on the print button click event:

// form1.page1.printBtn::click - (JavaScript, client)

if (form1.page1.subform1.address2.isNull || form1.page1.subform1.address2.rawValue == "") {

  form1.page1.subform2.name.rawValue = form1.page1.subform1.name.rawValue;

  form1.page1.subform2.address1.rawValue = form1.page1.subform1.address1.rawValue;

  form1.page1.subform2.city.rawValue = form1.page1.subform1.city.rawValue;

  form1.page1.subform2.state.rawValue = form1.page1.subform1.state.rawValue;

  form1.page1.subform2.zipCode.rawValue = form1.page1.subform1.zipCode.rawValue;

  form1.page1.subform1.presence = "hidden";

  form1.page1.subform2.presence = "visible";

}

xfa.host.print(1, "0", (xfa.host.numPages -1).toString(), 0, 0, 0, 0, 0);

The script checks for data in 'form1.page1.subform1.address2'. If there is no data, 'subform2' is populated from the applicable 'subform1' fields, 'subform1' is hidden, and 'subform2' is made visible.

The sample is attached.

Steve

View solution in original post

6 Replies

Avatar

Correct answer by
Former Community Member

It can be achieved using two sub-forms, one with 2 address lines and the other with 1 address line. You can see in the image, below, the two sub-forms are defined in the hierarchy view but 'subform2' is not visible. It has the same x and y coordinates and dimensions as 'subform1'.

foo.PNG

For demonstration purposes I added a print button and the following JavaScript on the print button click event:

// form1.page1.printBtn::click - (JavaScript, client)

if (form1.page1.subform1.address2.isNull || form1.page1.subform1.address2.rawValue == "") {

  form1.page1.subform2.name.rawValue = form1.page1.subform1.name.rawValue;

  form1.page1.subform2.address1.rawValue = form1.page1.subform1.address1.rawValue;

  form1.page1.subform2.city.rawValue = form1.page1.subform1.city.rawValue;

  form1.page1.subform2.state.rawValue = form1.page1.subform1.state.rawValue;

  form1.page1.subform2.zipCode.rawValue = form1.page1.subform1.zipCode.rawValue;

  form1.page1.subform1.presence = "hidden";

  form1.page1.subform2.presence = "visible";

}

xfa.host.print(1, "0", (xfa.host.numPages -1).toString(), 0, 0, 0, 0, 0);

The script checks for data in 'form1.page1.subform1.address2'. If there is no data, 'subform2' is populated from the applicable 'subform1' fields, 'subform1' is hidden, and 'subform2' is made visible.

The sample is attached.

Steve

Avatar

Level 7

Thanks. I'll give this a try.

MDawn

Avatar

Level 7

I tried the script and am not having much success. The first time  I tried it, address line 2 was not suppressed. Also, I have script in the prePrint and postPrint on text fields to suppress printing the underlining and that wasn't working.

I reworked the form to change the subform and field naming to match the script, thinking maybe I had edited wrong. Now it won't print at all.

I've attached my form. I appreciate any help you can give me.

Thanks,

MDawn

Avatar

Former Community Member

There are a number of issues, including the JavaScript field references I used in my example don't match your form. Additionally, could you explain what you are trying to accomplish in the pre-print and post-print events?

Avatar

Level 7

I have underlining of certain text fields so the user know it's a field.

The prePrint and postPrint are to suppress the underlining in the field

from printing and then to put the underline back after printing.

Concerning the field references. I thought I had changed them to match

and still use the fields in my design.

Any help is much appreciated.

Thanks,

Margaret Dawn

Supervisor - Documentation

W: 630-850-1065

Avatar

Level 7

I've been trying this some more. I can replicate your form in my own project, starting from a blank form. And it works fine. If I add any more subforms, then the Print Form button doesn't work. Am I missing something about the scripting? I'll attach my experimentation form.

Thanks,

MDawn

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----