Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript form function toFixed only displaying one digit in some cases #17540

Closed
rtpt-romankarwacik opened this issue Jan 19, 2024 · 2 comments · Fixed by #17541
Closed

JavaScript form function toFixed only displaying one digit in some cases #17540

rtpt-romankarwacik opened this issue Jan 19, 2024 · 2 comments · Fixed by #17541
Assignees
Labels

Comments

@rtpt-romankarwacik
Copy link

Attach (recommended) or Link to PDF file here:
test.pdf

Configuration:

  • Web browser and its version: Firefox 121.0.1
  • Operating system and its version: Fedora 39
  • PDF.js version: PDF.js: 4.0.240 [ffbfd68]
  • Is a browser extension: Yes? pdf.js it integrated into Firefox

Steps to reproduce the problem:

  1. Open the attached PDF file
  2. Type a number into the textfield

What is the expected behavior?
For example in Chromium or Okular the resulting Numbers have a fixed number of decimal digits (3):
image

What went wrong?
In Firefox, only one decimal digit is shown for one value, while the other is properly displayed:
image

The underlying latex code used to produce the PDF:

\documentclass{article}
\usepackage{hyperref}

\begin{document}
\begin{Form}
\TextField[name=f1]{\null} $\cdot 0.3 =$
\TextField[calculate={
event.value = (parseInt(this.getField('f1').value) * 0.3).toFixed(3);
},readonly=true,name=f1calc]{\null}
\TextField[calculate={
this.getField('f1').value;
event.value = (0.33333).toFixed(3);
},readonly=true,name=f2calc]{\null}
\end{Form}
\end{document}
@Snuffleupagus
Copy link
Collaborator

The formatting seems to be clobbered at the following line, however I don't know what (if any) effect simply keeping all existing decimal places would have in the general case?

this._value = !isNaN(_value) ? parseFloat(_value) : value;

@calixteman calixteman self-assigned this Jan 19, 2024
@calixteman
Copy link
Contributor

Yep it's because we're using the value field which should be a number when it's a "number" in the Calculate process:

runCalculate(source, event) {

calixteman added a commit to calixteman/pdf.js that referenced this issue Jan 19, 2024
…la#17540)

And avoid to not format a field when the value is 0.
calixteman added a commit to calixteman/pdf.js that referenced this issue Jan 19, 2024
…la#17540)

And avoid to not format a field when the value is 0.
calixteman added a commit that referenced this issue Jan 20, 2024
Use the original value of a field when propagating event (fixes #17540)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants