Solved

Print K2 form

  • 29 November 2022
  • 5 replies
  • 17 views

Badge +1
  • Rookie
  • 2 replies

I have created a form and I have added a button called "print" so that the form can be printed when clicking. I created a data label with the following expression <script>window.print();</script> and added a transfer data rule to the print button but it did not work. Can someone help me with that please?





Thank you!

icon

Best answer by TinTex 30 November 2022, 16:27

View original

5 replies

How was this implemented?





Do you have a data label control where the 'Literal' Property is enabled, and the Prevent XSS is disabled?





Are you setting the data label with the script as the value?





Or do you have the <script>window.print();</script> defined in a expression, and the mapping the expression to the data label with the settings described above?





You can also do a:



when form is initialized



- set property control of the data label described above, setting the expression to the expression with the '<script>window.print();</script>' defined, this may ensure that the print windows will load after the form has fully loaded

Badge +1
A data label is set:
&lt;script type="text/javascript">$(document).ready(function() { $("[title='Action Button']").click(function() {window.print()});});&lt;/script&gt;

It works now. But the "print" button shows when trying to print and I would like to hide it. I created the following rule:

"when button print is clicked
them hide the button print form control "

but it does not work

There is a data label set:
Text/JavaScript script type="$" (document).
prepared (function() $("[title='Action Button']").
function() "window.print()");;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



Now it operates. However, I would like to hide the "print" button that appears when trying to print. The following rule was I made:



"When the button print is clicked, the button print form control is hidden."



but it is unsuccessful.

Maybe the print() JavaScript executed before Smartforms hide button rule did.





You can try creating an expression, and adding the '<script>window.print();</script>' to that expression. Then clear out your data label but just keep the 'Literal' Property as enabled, and the Prevent XSS as disabled.





Then:



"when button print is clicked
them hide the button print form control



set button print control's properties (set the expression to the one containing '<script>window.print();</script>')"

Badge +1
It worked. Thak you!

Reply