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

Acroform Textfield doesn't set the stored user's value in the html element if it has a default value #16723

Closed
TaTo30 opened this issue Jul 22, 2023 · 3 comments

Comments

@TaTo30
Copy link
Contributor

TaTo30 commented Jul 22, 2023

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

Configuration:

  • Web browser and its version: Firefox 115
  • Operating system and its version: Windows 10
  • PDF.js version: 3.7.107
  • Is a browser extension: no

Implementing a web application with pdfjs-dist package and enabling forms, if a textfield has a default value it always will render with that value even if there are a different value in storage.

sample

The expected behavior is for textfields hold the user's value.

I think the issue is probably caused by this code:

element.setAttribute("value", fieldFormattedValues ?? textContent);

const elementData = {
  userValue: textContent,
  formattedValue: fieldFormattedValues,
  lastCommittedValue: null,
  commitKey: 1,
};

if (this.data.multiLine) {
  element = document.createElement("textarea");
  element.textContent = fieldFormattedValues ?? textContent; // <-- here
  if (this.data.doNotScroll) {
    element.style.overflowY = "hidden";
  }
} else {
  element = document.createElement("input");
  element.type = "text";
  element.setAttribute("value", fieldFormattedValues ?? textContent); // <-- also here...
  if (this.data.doNotScroll) {
    element.style.overflowX = "hidden";
  }
}

textContent has the stored user's value and fieldFormattedValues look to has the default value, you can see that fieldFormattedValues has more precedence than textContent, maybe switching the precedence could fix it.

@TaTo30
Copy link
Contributor Author

TaTo30 commented Jul 22, 2023

I also noticed when blur event is dispatched textfield restores to default because fieldFormattedValues has the default value, so i think both problems could be fixed by adding this line:

// if `textContent` has user's value `fieldFormattedValues` isn't needed
fieldFormattedValues = textContent ? null : fieldFormattedValues

const elementData = {
  userValue: textContent,
  formattedValue: fieldFormattedValues,
  lastCommittedValue: null,
  commitKey: 1
};

@Snuffleupagus
Copy link
Collaborator

PDF.js version: 3.7.107

That version is no longer supported, please find the latest releases at https://mozilla.github.io/pdf.js/getting_started/#download

Implementing a web application with pdfjs-dist package and enabling forms, if a textfield has a default value it always will render with that value even if there are a different value in storage.

This would be much easier to reproduce/understand with a runnable example, as asked for in https://github.com/mozilla/pdf.js/blob/master/.github/CONTRIBUTING.md

@Snuffleupagus
Copy link
Collaborator

Duplicate of #17046

@Snuffleupagus Snuffleupagus marked this as a duplicate of #17046 Sep 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants