Wednesday 29 August 2018

Count the Number of Words

How to Count/limit number of words entered by a user?

If you want to go beyond the basic restrictions or want to apply some more logical boundations then Regular Expression would be the right solution.

Below is the example to restrict the user to not enter more than 5 words.


Limit Words


Snippet:

if (xfa.event.newText.match(/\b\w+?\b/g).length > 5)

          xfa.event.change = "";
          app.alert("Maximum of 5 words are allowed");


Source: https://www.dropbox.com/s/a0vy1z1yvne7ut3/limit%20to%205%20words.pdf?dl=0

Show login name of the user

How to get the Username/ Login Name of the user who filled the form?

Due to security reason in PDF, this task becomes quite difficult to achieve and is only feasible for the intranet environment.
Firstly, you need to create a Trusted Function at the folder level script which checks the login name and returns the value to a form field. Here the hierarchy of the LC form is important. The result will map to the specific field in the form.

Place the following script in the Javascript folder of Acrobat or Reader depending on your requirement:
For Example:
C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Javascripts
Or,
C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\Javascripts


var TrustMe = app.trustedFunction(function(doc){app.beginPriv(); var IdentField = this.xfa.form.Form1.Page1.LoginUserName;IdentField.rawValue = this.identity.loginName;  app.endPriv(); });

Now, the main part is done and you just need to call the function which is placed at the folder level JavaScript.  

Put this script in the form:ready event of the form or any button to call the function
 

event.target.TrustMe(event.target);

Show Login Name


Download the files from the following link and place the .js file at the JavaScripts folder mentioned above and then open the PDF and click "Get" button.

Source: https://www.dropbox.com/s/qwtvpsv68ocxdvy/GetUserName.zip?dl=0

Cursor focus on specific field

To move the focus on the specific field.


Many a times, we need the cursor to move to specific field based on our requirement. The most common scenarios are - validation of fields and Tab Order.

Use the following script to focus.

Snippet:

if (event.fieldFull) {
    getField("NameOfNextFieldGoesHere").setFocus();
}



Radio Button as mandatory field

How to make the radio button group as required.

By default, LC Designer doesn't validate the NULL value of the Radio Button Group as Required Field. We need to use JavaScript to implement the logic.
In my example I used a button to first validate the Radio Button Group and if it is not NULL then it sends an email.

Radio Button Required
Snippet:

if(RadioButtonList.yes.rawValue == null && RadioButtonList.no.rawValue == null)
{
app.alert("Please select the option");
}

else
{
var eid = "test@test.com";
var sub = "test subject";
var bdy = "Sample Body";
event.target.submitForm({cURL:"mailto:" + eid + "?subject=" + sub + "&body=" + bdy ,cSubmitAs:"PDF",cCharset:"utf-8"});
}



Source: https://www.dropbox.com/s/912u03ku8au3fcx/RadioButtonRequired.pdf?dl=0

Convert Numbers into Words

WordNum is the function which returns the English text equivalent of a given number.

For Example:
Expression
Returns
WordNum(123.45)One Hundred and Twenty-three Dollars
WordNum(123.45, 1)One Hundred and Twenty-three Dollars
WordNum(1154.67, 2)One Thousand One Hundred Fifty-four Dollars And Sixty-seven Cents
WordNum(43, 2)Forty-three Dollars And Zero Cents
WordNum(Amount[0], 2)
This example uses the first occurrence of Amount as the conversion number.
 However, there is a limitation in this fuction. It only converts the two decimal values and if you want to English conversion for more than 2 decimals then you need to use the JavaScript to modify the function.
This is required in case of currency conversion for example Omani Rial, where 3 decimal values are acceptable.

Note: This function runs in Formcalc language so all coding needs to be done in FormCalc only.


Number To Word
Snippet:

if ($.rawValue == "OMR") then
var last = right(TextField1,3)
var part1 = Concat(WordNum(TextField1), " rials And ")
var part2 = Concat(WordNum(last) , " baisa")
TextField2.rawValue = Concat(part1 , part2)
endif


Source: https://www.dropbox.com/s/dvn68wm3oybs43l/sampleNumToWord.pdf?dl=0

Email Submit Restrictions

1. To apply restriction in a form which needs to pass before submit.
2. If the user cancels the submit process then perform post submit operation and validate again.

Verifying the restrictions is easy in the form, but to capture the control after a user clicks on Submit is tricky.

In my example, I am verifying the Phone Number on submit and hiding the Submit Button itself.
The scenario is that the form can only be submitted once.

However, if the user clicks on Submit Button and cancel the draft email for any reason then the whole process should be nullified and Submit Button should remain active.

This can be done by using the try catch block. And after capturing the specific exception of user cancelled operation, we can perform post submit operation.

Submit Cancelled
Snippet:

try
var eid = "dummy@test.com";
var sub = "This is a dummy Subject Line";
var bdy = "Sample Body";

if(TextField1.rawValue == null || TextField1.rawValue == "" || TextField1.rawValue.length != 10)
{
app.alert("Please enter correct phone number");
}
if(TextField1.rawValue.length == 10)
{
this.presence = "hidden";
event.target.submitForm({cURL:"mailto:" + eid + "?subject=" + 'Anoop &amp Singh' + "&body=" + bdy ,cSubmitAs:"PDF",cCharset:"utf-8"});
}

}
catch(e)
{

if(e.toString() == "RaiseError: User canceled operation.")
{
this.presence = "visible";
}

}



About us




Acrobat and AEM Forms


PDF forms are easy to read and open on any platform i.e. Desktop, PC, Mobile devices, etc. However, creating PDF forms may be difficult sometimes. Getting the desired layout and adding dynamic properties into the form is not an easy job.

Adobe provides tools to create and interact with PDF like Acrobat and AEM Forms. Using JavaScript in a PDF brings life to the flat PDF document and enhances its capabilities.

AEM forms combine form authoring, management, and publishing along with correspondence management capabilities, document security, and integrated analytics to create engaging end-to-end experiences. Designed to work across web and mobile channels, AEM forms can be efficiently integrated into your business processes, reducing paper processes and errors while improving efficiency.

AEM form types
AEM forms let you extend new and existing forms to create:

  • pixel-perfect, paginated HTML and PDF forms that look almost like paper, or
  • adaptive forms that automatically render for a user's device and browser.

PDF forms

PDF forms can be filled offline, saved locally, and form data sent when you are next online. You can use 2D barcodes to capture form data, and use digital signatures to validate authenticity for users.   

HTML forms

HTML5 browser-based forms can be viewed on both mobile devices and desktop browsers. You can electronically sign HTML forms using Scribble or Adobe EchoSign.

Adaptive forms

Adaptive forms can dynamically adapt to user responses by adding or removing fields or sections as required. AEM lets you reuse Adobe XML form templates to create adaptive forms.

Logo1





Tuesday 28 August 2018

Calculation on dynamically added rows in a Table


Among many features that PDF provides, auto calculation of form fields is a very useful feature. Apart from the usual mathematical calculations, this feature can be exploited to calculate table rows based on data at runtime.

Use Case
Consider a scenario where the data is generated and fed to the table. The table must accommodate the incoming data dynamically at run time. It is imperative to determine the additional number of rows in the table as per user requirement at the same time.
How will we calculate to reflect the dynamic objects and how to reference these values?  
This article will help you to accomplish the task.



Solution
We use the following script:

FormCalc Script: sum(Table1.Row1[*].total.rawValue)

There are two essential things to be kept in mind to make the script work:


  1. Choose the script language as FormCalc in AEM Forms. By default, it is set to JavaScript.
  2.  The FormCalc function sum()  is simple to use. Make sure you know the object (that is, either the row or field) that is getting added dynamically. The [*] symbol is appended to the row which is getting repeated or with the field name if required.
In our use case example, only the row is repeating. So, we have not provided any value to the field.


For additional queries, please send your form to lcdesignerforms@gmail.com



Populate same XML data in multiple fields

How to populate the same XML data in multiple fields in AEM Forms?

By design, the XML data tag can only be mapped to one field in the form. But still, if you bind it with multiple fields then at runtime it fills the field that comes first in occurrence.

The Global Binding is also not of much use here. So the only option left is JavaScript.

Through JavaScript, we can assign the raw Value of multiple fields together.

In my example, I am using a Table to show multiple rows with data.

Populate Data

Code Snippet
var rowNodes = Table1.disqualifiedIndvDetails.instanceManager.count;

for (var nNodeCount = 0; nNodeCount < rowNodes ; nNodeCount ++)
{

     page2.Table2.disqualifiedIndvDetails.instanceManager.addInstance();
    page3.Table3.disqualifiedIndvDetails.instanceManager.addInstance();
   
    xfa.resolveNode("page2.Table2.disqualifiedIndvDetails["+nNodeCount+"].name").rawValue = xfa.resolveNode("Table1.disqualifiedIndvDetails["+nNodeCount+"].name").rawValue
    xfa.resolveNode("page2.Table2.disqualifiedIndvDetails["+nNodeCount+"].disReason").rawValue = xfa.resolveNode("Table1.disqualifiedIndvDetails["+nNodeCount+"].disReason").rawValue
    xfa.resolveNode("page2.Table2.disqualifiedIndvDetails["+nNodeCount+"].numMonths").rawValue = xfa.resolveNode("Table1.disqualifiedIndvDetails["+nNodeCount+"].numMonths").rawValue
   
    xfa.resolveNode("page3.Table3.disqualifiedIndvDetails["+nNodeCount+"].name").rawValue = xfa.resolveNode("Table1.disqualifiedIndvDetails["+nNodeCount+"].name").rawValue
    xfa.resolveNode("page3.Table3.disqualifiedIndvDetails["+nNodeCount+"].disReason").rawValue = xfa.resolveNode("Table1.disqualifiedIndvDetails["+nNodeCount+"].disReason").rawValue
    xfa.resolveNode("page3.Table3.disqualifiedIndvDetails["+nNodeCount+"].numMonths").rawValue = xfa.resolveNode("Table1.disqualifiedIndvDetails["+nNodeCount+"].numMonths").rawValue
}


 Source File: https://www.dropbox.com/s/1s0i3hoqzpnycsz/MultipleData.zip?dl=0