• No results found

Custom fields validation

N/A
N/A
Protected

Academic year: 2021

Share "Custom fields validation"

Copied!
7
0
0

Loading.... (view fulltext now)

Full text

(1)

PDF SHARE FORMS

Online, Offline, OnDemand

PDF forms and SharePoint are better together

Custom fields validation

PDF Share Forms

(2)

Online, Offline, OnDemand

PDF forms and SharePoint are better together

This guide will show how to make custom validation for fields in static AcroForms and Dynamic XFA forms.

1. Static AcroForm

Step 1.

Template

Following template will be used in this guide:

In this template are used following controls:

RegularButton1 – as custom submit button;

TextField2 – as example for custom “is not blank” and validation;

RadioButtonGroup4 – as example for custom “is not blank”.

Step 2.

Add script to RegularButton1 (PDF Form Tools

Properties

Actions):

Add “JavaScript” action.

Code:

var isBlank = false;

var blank = "Please fill following fields:"; var isNotValid = false;

var notValid = "Please check input data in following fields:"; //cannot be blank

if (this.getField('TextField2').value == "") {

blank = blank + "\n" + this.getField('TextField2').name; isBlank = true;

}

if (this.getField('RadioButtonGroup4').value == "Off") {

blank = blank + "\n" + this.getField('RadioButtonGroup4').name; isBlank = true;

}

2

780 Roosevelt, Irvine, CA 92620 • Tel +1 888 792 7871 • Fax +1 949 861 6447 • [email protected] • www.pdfshareforms.com
(3)

Online, Offline, OnDemand

PDF forms and SharePoint are better together

//validation text field must contain only lower case letters if (/^[a-z]*$/.test(this.getField('TextField2').value) == false) { notValid = notValid + "\n" + this.getField('TextField2').name; isNotValid = true; } //generate message var message = ""; if (isBlank == true) { message = blank + "\n" + "\n"; } if (isNotValid == true) {

message = message + notValid; }

//check all conditions

if ((isBlank == true) || (isNotValid == true)) { //show message

app.alert({ cMsg: message, cTitle: "Input data error" }); }

else {

//save form

eval("var sysData ="+this.getField("PDFSPSystemData").value);

this.submitForm({cURL: (sysData.WebURL || "")+"/_layouts/PDFForms/PDF.aspx", cSubmitAs: "PDF" });

}

This code will check if “TextField2” or “RadioButtonGroup4” are blank. Then it will validate data inside “TextField2” using

JavaScript Regular expressions – field must contain only lower case letters. Finally it will create error message to display

list of fields which are blank or need to be changed, or save this PDF form to SharePoint library.

Step 3.

Save template and deploy it to library

Step 4.

Runtime

Step 4.1.

Create new form and try to click on “RegularButton1” when all fields are blank:

3

780 Roosevelt, Irvine, CA 92620 • Tel +1 888 792 7871 • Fax +1 949 861 6447 • [email protected] • www.pdfshareforms.com
(4)

Online, Offline, OnDemand

PDF forms and SharePoint are better together

Step 4.2.

Error message appeared. Close it; add to text field some “wrong string” – with digits or upper case letters:

Step 4.3.

Close window again and fill all fields with right data: check one of radio buttons and text field with string

containing only lower case letters:

Now form can be submitted.

4

780 Roosevelt, Irvine, CA 92620 • Tel +1 888 792 7871 • Fax +1 949 861 6447 • [email protected] • www.pdfshareforms.com
(5)

Online, Offline, OnDemand

PDF forms and SharePoint are better together

2. Dynamic XFA form

Step 1.

Template

Following template will be used in this guide:

In this template are used following controls:

SubmitButton1 – submit button with additional scripted conditions;

DateTimeField1 – as example for custom “is not blank” and validation;

RadioButtonGroup1 – as example for custom “is not blank”.

Step 2.

Add script to SubmitButton1 (PDF Form Tools

Properties

Button Click):

Add “Scripted condition” condition to “If” section.

Code:

var isBlank = false;

var blank = "Please fill following fields:"; var isNotValid = false;

var notValid = "Please check input data in following fields:"; //cannot be blank

if (xfa.resolveNode("$data..DateTimeField1").value == null) {

blank = blank + "\n" + xfa.resolveNode("$data..DateTimeField1").name; isBlank = true;

}

if (xfa.resolveNode("$data..RadioButtonGroup1").value == null) {

blank = blank + "\n" + xfa.resolveNode("$data..RadioButtonGroup1").name; isBlank = true;

}

5

780 Roosevelt, Irvine, CA 92620 • Tel +1 888 792 7871 • Fax +1 949 861 6447 • [email protected] • www.pdfshareforms.com
(6)

Online, Offline, OnDemand

PDF forms and SharePoint are better together

//date time field validation - mm/dd/yyyy var rez =

/^(0[1-9]|1[0-2])\/(0[1-9]|1\d|2\d|3[01])\/(19|20)\d{2}$/.test(xfa.resolveNode("$data..DateTimeField1").value); if (rez == false) {

notValid = notValid + "\n" + xfa.resolveNode("$data..DateTimeField1").name; isNotValid = true; } //generate message var message = ""; if (isBlank == true) { message = blank + "\n" + "\n"; } if (isNotValid == true) {

message = message + notValid; }

//check all conditions

if ((isBlank == true) || (isNotValid == true)){ //show message

xfa.host.messageBox(message, "Input data error", 0); return false;

} else {

//proceed to save action return true;

}

This code will check if “DateTimeField1” or “RadioButtonGroup1” are blank. Then it will validate data inside

“DateTimeField1” using JavaScript Regular expressions – field must contain data formatted as mm/dd/yyyy. Finally it will

create error message to display list of fields which are blank or need to be changed, or save this PDF form to SharePoint

library.

Step 3.

Save template and deploy it to library

Step 4.

Runtime

Step 4.1.

Create new form and try to click on “Save” when all fields are blank:

6

780 Roosevelt, Irvine, CA 92620 • Tel +1 888 792 7871 • Fax +1 949 861 6447 • [email protected] • www.pdfshareforms.com
(7)

Online, Offline, OnDemand

PDF forms and SharePoint are better together

Step 4.2.

Error message appeared. Close it, add to text field some “wrong string” – date like “22/22/2013”:

Step 4.3.

Close window again and fill all fields with right data: check one of radio buttons and text field with string

containing right date format:

Now form can be submitted.

7

780 Roosevelt, Irvine, CA 92620 • Tel +1 888 792 7871 • Fax +1 949 861 6447 • [email protected] • www.pdfshareforms.com
www.pdfshareforms.com

References

Related documents

The User-Defined Fields following window displays custom fields you create and associate with the selected Address Book entry, customer service case, campaign, opportunity, or

FDMS Nashville: String with numbers only (19) All other processors: String with numbers only (20) Table 12 General Card-Present Request Fields (Continued). Field

[r]

This paper will trace the development of  trace the development of  Tesla's understanding of Vedic Science, his correspondence with Lord Tesla's understanding of Vedic Science,

When adding fields to a document, there might be times when you want to let your recipient select options on the document and you might not be sure if you should use check boxes

BCLC, Barcelona Clinic Liver Cancer; HCC, hepatocellular carcinoma; LTC, local tumor control; OS, overall survival; PBT, proton beam therapy; PFS, progression free survival..

In the Insert Merge Field window, make sure that the Database Fields radio button is selected and click on the CustomerName field.. Click on the

Critical levels and associated error rates were estimated for each sampling dates for the following plant and soil N indicators: (i) petiole NO 3 -N concentrations (dry weight basis),