Skip to content

Commit

Permalink
feat: preserve autosubmit
Browse files Browse the repository at this point in the history
  • Loading branch information
dbajpeyi committed Dec 5, 2024
1 parent 35e9191 commit 1098e1b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 20 deletions.
12 changes: 8 additions & 4 deletions dist/autofill-debug.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions dist/autofill.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions src/Form/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -896,18 +896,23 @@ class Form {
// After autofill we check if form values match the data provided…
const formValues = this.getValuesReadyForStorage();
const hasNoCredentialsData = !formValues.credentials?.username && !formValues.credentials?.password;
const hasOnlyEmail = formValues.identities && Object.keys(formValues.identities).length === 1 && formValues.identities.emailAddress;
const hasOnlyEmail =
formValues.identities && Object.keys(formValues.identities ?? {}).length === 1 && formValues.identities?.emailAddress;

const hasOnlyOneCredentialOrEmail =
Boolean(formValues.credentials?.username) !== Boolean(formValues.credentials?.password) ||
(hasOnlyEmail && hasNoCredentialsData);
const areAllFormValuesKnown = Object.keys(formValues[dataType] || {}).every(
(subtype) => formValues[dataType][subtype] === data[subtype],
);
// If all form values are known, but we only have a single credential field - then we want to prompt a partial save with username,

// If we only have a single credential field - then we want to prompt a partial save with username,
// So that in multi step forms (like reset-password), we can identify which username was picked, or complete a password save.
if (areAllFormValuesKnown && !hasOnlyOneCredentialOrEmail) {
// …if we know all the values do not prompt to store data
if (hasOnlyOneCredentialOrEmail) {
this.shouldPromptToStoreData = true;
this.shouldAutoSubmit = this.device.globalConfig.isMobileApp;
} else if (areAllFormValuesKnown) {
// …if it's a normal form with more than one field and if we know all the values do not prompt to store data
this.shouldPromptToStoreData = false;
// reset this to its initial value
this.shouldAutoSubmit = this.device.globalConfig.isMobileApp;
Expand Down
12 changes: 8 additions & 4 deletions swift-package/Resources/assets/autofill-debug.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions swift-package/Resources/assets/autofill.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1098e1b

Please sign in to comment.