-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathaddTextField.js
80 lines (73 loc) · 2.02 KB
/
addTextField.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
'use strict';
const signnow = require('@signnow/api-client')({
credentials: 'BASE64_ENCODED_CLIENT_CREDENTIALS',
production: true, // if false then uses eval server
});
const addTextField = signnow.document.update;
const id = 'DOCUMENT_ID_GOES_HERE';
const token = 'YOUR_ACCESS_TOKEN';
/**
* @typedef {Object} SignatureField
* @property {number} page_number - page number of document
* @property {string} type - type of field
* @property {string} name - unique name of the field
* @property {string} role - role name
* @property {boolean} required - required field
* @property {number} height - height of the field
* @property {number} width - width of the field
* @property {number} x - X coordinate of the field
* @property {number} y - Y coordinate of the field
* @property {?string} prefilled_text - prefilled value of a field
* @property {?string} validator_id - input validator id
* @property {?string} label
*/
/**
* @type {Object}
* @property {number} client_timestamp - local time of user
* @property {SignatureField[]} fields
*/
const fields = {
client_timestamp: 1527859375,
fields: [
{
page_number: 0,
type: 'text',
name: 'TextName',
role: 'Singer 1',
prefilled_text: '123',
validator_id: '1f9486ae822d30ba3df2cb8e65303ebfb8c803e8',
label: 'TextLabel',
required: true,
height: 40,
width: 50,
x: 217,
y: 120,
},
],
};
/**
* @param {Object} res
* @param {string} res.id - an id of document
* @param {Object[]} res.signatures - signature and initial elements
* @param {Object[]} res.texts - text and enumeration elements
* @param {Object[]} res.checks - checkbox elements
* @param {Object[]} res.attachments - attachment elements
* @param {Object[]} res.radiobuttons - radiobutton elements
*/
const handleResponse = res => {
console.log(res);
};
const handleError = err => {
console.error(err);
};
addTextField({
id,
fields,
token,
}, (err, res) => {
if (err) {
handleError(err);
} else {
handleResponse(res);
}
});