Skip to content

Commit e9be9f4

Browse files
committed
[ci skip] fix date select dialog not showing; fix incorrect state when cancel print
1 parent 60811ac commit e9be9f4

File tree

2 files changed

+25
-31
lines changed

2 files changed

+25
-31
lines changed

composeApp/src/desktopMain/kotlin/de/l4zs/html2pdfform/backend/converter/HtmlConverter.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ class HtmlConverter(
7474
pdf.add(Chunk("")) // prevent exception when no content is added
7575
writer.setAdditionalAction(PdfWriter.WILL_PRINT, PdfAction.javaScript(Actions.willPrint, writer))
7676
writer.setAdditionalAction(PdfWriter.DID_PRINT, PdfAction.javaScript(Actions.didPrint, writer))
77-
writer.setPageAction(PdfWriter.PAGE_OPEN, PdfAction.javaScript(Actions.pageOpen, writer))
7877

7978
pdf.setHeaderFooter(config)
8079
writeIntro(pdf, locationHandler, writer)

composeApp/src/desktopMain/kotlin/de/l4zs/html2pdfform/backend/util/Actions.kt

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,46 @@ package de.l4zs.html2pdfform.backend.util
22

33
/** Actions are JavaScript snippets that can be executed in a PDF form. */
44
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+
*/
1011
val willPrint =
1112
"""
1213
global.skipValidation = true;
13-
global.passwords = [];
14+
global.isPrinting = true;
1415
for (var i = 0; i < this.numFields; i++) {
1516
var f = this.getField(this.getNthFieldName(i));
1617
if (f && f.type == "text") {
1718
f.display = display.visible;
1819
if (f.value == "") {
19-
f.value = " ";
20-
if (f.password) {
21-
f.password = false;
22-
global.passwords.push(f.name);
23-
}
20+
f.value = "";
2421
}
2522
}
2623
}
24+
global.isPrinting = false;
25+
global.skipValidation = false;
2726
""".trimIndent()
2827

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+
*/
2934
val didPrint =
3035
"""
36+
global.skipValidation = true;
3137
for (var i = 0; i < this.numFields; i++) {
3238
var f = this.getField(this.getNthFieldName(i));
3339
if (f && f.type == "text") {
34-
if (f.value == " ") {
40+
if (f.value == "") {
3541
f.value = "";
3642
}
3743
}
3844
}
39-
for (var i = 0; i < global.passwords.length; i++) {
40-
var f = this.getField(global.passwords[i]);
41-
f.password = true;
42-
}
4345
global.skipValidation = false;
4446
""".trimIndent()
4547

@@ -74,9 +76,7 @@ object Actions {
7476
*/
7577
fun formatDate(format: String): String =
7678
"""
77-
if (!global.skipValidation) {
78-
AFDate_FormatEx("$format");
79-
}
79+
AFDate_FormatEx("$format");
8080
""".trimIndent()
8181

8282
/**
@@ -87,9 +87,7 @@ object Actions {
8787
*/
8888
fun formatTime(format: String): String =
8989
"""
90-
if (!global.skipValidation) {
91-
AFTime_FormatEx("$format");
92-
}
90+
AFTime_FormatEx("$format");
9391
""".trimIndent()
9492

9593
/**
@@ -100,9 +98,7 @@ object Actions {
10098
*/
10199
fun keystrokeDate(format: String): String =
102100
"""
103-
if (!global.skipValidation) {
104-
AFDate_KeystrokeEx("$format");
105-
}
101+
AFDate_KeystrokeEx("$format");
106102
""".trimIndent()
107103

108104
/**
@@ -113,9 +109,7 @@ object Actions {
113109
*/
114110
fun keystrokeTime(format: String): String =
115111
"""
116-
if (!global.skipValidation) {
117-
AFTime_Keystroke("$format");
118-
}
112+
AFTime_Keystroke("$format");
119113
""".trimIndent()
120114
}
121115

@@ -199,14 +193,15 @@ object Actions {
199193
/** JavaScript snippets for Placeholder fields. */
200194
object Placeholder {
201195
/**
202-
* Formats the placeholder text.
196+
* Formats the field to show a placeholder text when empty.
197+
* When printing, the placeholder isn't visible.
203198
*
204199
* @param placeholder Placeholder text.
205200
* @return JavaScript snippet.
206201
*/
207202
fun formatPlaceholder(placeholder: String) =
208203
"""
209-
if (!event.value) {
204+
if (event.value == "" && !global.isPrinting) {
210205
event.value = "$placeholder";
211206
event.target.textColor = color.ltGray;
212207
} else {

0 commit comments

Comments
 (0)