@@ -2,6 +2,47 @@ package de.l4zs.html2pdfform.backend.util
2
2
3
3
/* * Actions are JavaScript snippets that can be executed in a PDF form. */
4
4
object Actions {
5
+ val pageOpen =
6
+ """
7
+ global.skipValidation = false;
8
+ """ .trimIndent()
9
+
10
+ val willPrint =
11
+ """
12
+ global.skipValidation = true;
13
+ global.passwords = [];
14
+ for (var i = 0; i < this.numFields; i++) {
15
+ var f = this.getField(this.getNthFieldName(i));
16
+ if (f && f.type == "text") {
17
+ f.display = display.visible;
18
+ if (f.value == "") {
19
+ f.value = " ";
20
+ if (f.password) {
21
+ f.password = false;
22
+ global.passwords.push(f.name);
23
+ }
24
+ }
25
+ }
26
+ }
27
+ """ .trimIndent()
28
+
29
+ val didPrint =
30
+ """
31
+ for (var i = 0; i < this.numFields; i++) {
32
+ var f = this.getField(this.getNthFieldName(i));
33
+ if (f && f.type == "text") {
34
+ if (f.value == " ") {
35
+ f.value = "";
36
+ }
37
+ }
38
+ }
39
+ for (var i = 0; i < global.passwords.length; i++) {
40
+ var f = this.getField(global.passwords[i]);
41
+ f.password = true;
42
+ }
43
+ global.skipValidation = false;
44
+ """ .trimIndent()
45
+
5
46
/* * JavaScript snippets for Checkbox fields. */
6
47
object Checkbox {
7
48
/* *
@@ -33,7 +74,9 @@ object Actions {
33
74
*/
34
75
fun formatDate (format : String ): String =
35
76
"""
36
- AFDate_FormatEx("$format ");
77
+ if (!global.skipValidation) {
78
+ AFDate_FormatEx("$format ");
79
+ }
37
80
""" .trimIndent()
38
81
39
82
/* *
@@ -44,7 +87,9 @@ object Actions {
44
87
*/
45
88
fun formatTime (format : String ): String =
46
89
"""
47
- AFTime_FormatEx("$format ");
90
+ if (!global.skipValidation) {
91
+ AFTime_FormatEx("$format ");
92
+ }
48
93
""" .trimIndent()
49
94
50
95
/* *
@@ -55,7 +100,9 @@ object Actions {
55
100
*/
56
101
fun keystrokeDate (format : String ): String =
57
102
"""
58
- AFDate_KeystrokeEx("$format ");
103
+ if (!global.skipValidation) {
104
+ AFDate_KeystrokeEx("$format ");
105
+ }
59
106
""" .trimIndent()
60
107
61
108
/* *
@@ -66,7 +113,9 @@ object Actions {
66
113
*/
67
114
fun keystrokeTime (format : String ): String =
68
115
"""
69
- AFTime_Keystroke("$format ");
116
+ if (!global.skipValidation) {
117
+ AFTime_Keystroke("$format ");
118
+ }
70
119
""" .trimIndent()
71
120
}
72
121
@@ -76,7 +125,7 @@ object Actions {
76
125
val keystrokeNumber =
77
126
"""
78
127
var numberRegex = new RegExp(/^-?[0-9]*$/);
79
- if (!event.willCommit && event.change && !global.isResettingForm ) {
128
+ if (!event.willCommit && event.change && !global.skipValidation ) {
80
129
event.rc = numberRegex.test(event.change);
81
130
}
82
131
""" .trimIndent()
@@ -93,7 +142,7 @@ object Actions {
93
142
message : String ,
94
143
): String =
95
144
"""
96
- if (event.value && !global.isResettingForm ) {
145
+ if (event.value && !global.skipValidation ) {
97
146
var isLess = event.value < $min ;
98
147
if (isLess) {
99
148
app.alert("$message ");
@@ -114,7 +163,7 @@ object Actions {
114
163
message : String ,
115
164
): String =
116
165
"""
117
- if (event.value && !global.isResettingForm ) {
166
+ if (event.value && !global.skipValidation ) {
118
167
var isMore = event.value > $max ;
119
168
if (isMore) {
120
169
app.alert("$message ");
@@ -137,7 +186,7 @@ object Actions {
137
186
message : String ,
138
187
): String =
139
188
"""
140
- if (event.value && !global.isResettingForm ) {
189
+ if (event.value && !global.skipValidation ) {
141
190
var isInvalid = Math.abs(event.value - $base ) % $step > 0;
142
191
if (isInvalid) {
143
192
app.alert("$message ");
@@ -159,10 +208,8 @@ object Actions {
159
208
"""
160
209
if (!event.value) {
161
210
event.value = "$placeholder ";
162
- event.target.display = display.noPrint;
163
211
event.target.textColor = color.ltGray;
164
212
} else {
165
- event.target.display = display.visible;
166
213
event.target.textColor = color.black;
167
214
}
168
215
""" .trimIndent()
@@ -236,7 +283,7 @@ object Actions {
236
283
*/
237
284
val buttonDown =
238
285
"""
239
- global.isResettingForm = true;
286
+ global.skipValidation = true;
240
287
""" .trimIndent()
241
288
242
289
/* *
@@ -245,7 +292,7 @@ object Actions {
245
292
*/
246
293
val buttonUp =
247
294
"""
248
- global.isResettingForm = false;
295
+ global.skipValidation = false;
249
296
""" .trimIndent()
250
297
}
251
298
@@ -307,7 +354,7 @@ object Actions {
307
354
message : String ,
308
355
): String =
309
356
"""
310
- if (event.value && !global.isResettingForm ) {
357
+ if (event.value && !global.skipValidation ) {
311
358
var isLess = event.value.length < $minLength ;
312
359
if (isLess) {
313
360
app.alert("$message ");
@@ -331,7 +378,7 @@ object Actions {
331
378
): String =
332
379
"""
333
380
var regex = new RegExp(/$pattern /);
334
- if (event.value && !global.isResettingForm ) {
381
+ if (event.value && !global.skipValidation ) {
335
382
var isValid = regex.test(event.value);
336
383
if (!isValid) {
337
384
app.alert("${message ? : defaultMessage} ");
0 commit comments