@@ -2,44 +2,46 @@ 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
-
5
+ /* *
6
+ * When printing, placeholders should not be visible. Text fields where the
7
+ * value is empty can potentially be placeholders. Re-assigning the value
8
+ * to an empty string calls the format action again, where the placeholder
9
+ * won't be set because isPrinting is true.
10
+ */
10
11
val willPrint =
11
12
"""
12
13
global.skipValidation = true;
13
- global.passwords = [] ;
14
+ global.isPrinting = true ;
14
15
for (var i = 0; i < this.numFields; i++) {
15
16
var f = this.getField(this.getNthFieldName(i));
16
17
if (f && f.type == "text") {
17
18
f.display = display.visible;
18
19
if (f.value == "") {
19
- f.value = " ";
20
- if (f.password) {
21
- f.password = false;
22
- global.passwords.push(f.name);
23
- }
20
+ f.value = "";
24
21
}
25
22
}
26
23
}
24
+ global.isPrinting = false;
25
+ global.skipValidation = false;
27
26
""" .trimIndent()
28
27
28
+ /* *
29
+ * After printing, placeholders should be visible again. Text fields
30
+ * where the value is empty can potentially be placeholders. Re-assigning
31
+ * the value to an empty string calls the format action again, where
32
+ * the placeholder will be set again because isPrinting is false.
33
+ */
29
34
val didPrint =
30
35
"""
36
+ global.skipValidation = true;
31
37
for (var i = 0; i < this.numFields; i++) {
32
38
var f = this.getField(this.getNthFieldName(i));
33
39
if (f && f.type == "text") {
34
- if (f.value == " ") {
40
+ if (f.value == "") {
35
41
f.value = "";
36
42
}
37
43
}
38
44
}
39
- for (var i = 0; i < global.passwords.length; i++) {
40
- var f = this.getField(global.passwords[i]);
41
- f.password = true;
42
- }
43
45
global.skipValidation = false;
44
46
""" .trimIndent()
45
47
@@ -74,9 +76,7 @@ object Actions {
74
76
*/
75
77
fun formatDate (format : String ): String =
76
78
"""
77
- if (!global.skipValidation) {
78
- AFDate_FormatEx("$format ");
79
- }
79
+ AFDate_FormatEx("$format ");
80
80
""" .trimIndent()
81
81
82
82
/* *
@@ -87,9 +87,7 @@ object Actions {
87
87
*/
88
88
fun formatTime (format : String ): String =
89
89
"""
90
- if (!global.skipValidation) {
91
- AFTime_FormatEx("$format ");
92
- }
90
+ AFTime_FormatEx("$format ");
93
91
""" .trimIndent()
94
92
95
93
/* *
@@ -100,9 +98,7 @@ object Actions {
100
98
*/
101
99
fun keystrokeDate (format : String ): String =
102
100
"""
103
- if (!global.skipValidation) {
104
- AFDate_KeystrokeEx("$format ");
105
- }
101
+ AFDate_KeystrokeEx("$format ");
106
102
""" .trimIndent()
107
103
108
104
/* *
@@ -113,9 +109,7 @@ object Actions {
113
109
*/
114
110
fun keystrokeTime (format : String ): String =
115
111
"""
116
- if (!global.skipValidation) {
117
- AFTime_Keystroke("$format ");
118
- }
112
+ AFTime_Keystroke("$format ");
119
113
""" .trimIndent()
120
114
}
121
115
@@ -199,14 +193,15 @@ object Actions {
199
193
/* * JavaScript snippets for Placeholder fields. */
200
194
object Placeholder {
201
195
/* *
202
- * Formats the placeholder text.
196
+ * Formats the field to show a placeholder text when empty.
197
+ * When printing, the placeholder isn't visible.
203
198
*
204
199
* @param placeholder Placeholder text.
205
200
* @return JavaScript snippet.
206
201
*/
207
202
fun formatPlaceholder (placeholder : String ) =
208
203
"""
209
- if (! event.value) {
204
+ if (event.value == "" && !global.isPrinting ) {
210
205
event.value = "$placeholder ";
211
206
event.target.textColor = color.ltGray;
212
207
} else {
0 commit comments