Protect manual edits from autofill
A reported Chrome autofill interaction replaced other fields when a phone number was entered. Decide which fields the app can safely fill.
Protect manually entered fields from autofill
An independent web example inspired by the original reference.
Enter only the department yourself, press “Apply suggestions,” and confirm the department name remains.
Implementation steps
- Track for each field whether the user has edited it, for fields that receive auto suggestions.
- Apply auto suggestions only to fields that are both untouched and empty. Fields the user manually cleared count as edited.
- In form implementation, keep edit state alongside values, and check it right before applying async suggestions that arrive late.
Acceptance check
Neither fields you rewrote nor fields you manually cleared get overwritten again.
View sample code
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Protect manually entered fields from autofill</title>
<style>
* { box-sizing: border-box; }
body {
margin: 0;
padding: 16px;
background: #23232a;
color: #f4f0ea;
font: 16px/1.6 system-ui, sans-serif;
}
label, output, strong, audio, progress { display: block; margin: 6px 0; }
input, select, button { max-width: 100%; font: inherit; }
input, select { padding: 4px 7px; }
button {
margin: 4px 0;
padding: 5px 12px;
cursor: pointer;
border: 1px solid #b5a399;
border-radius: 6px;
}
:focus-visible { outline: 3px solid #ffad73; outline-offset: 2px; }
audio { width: 100%; }
[hidden] { display: none !important; }
</style>
</head>
<body>
<label>Department <input id="team"></label>
<label>Office <input id="office"></label>
<button id="apply">Apply suggestions</button>
<output id="result"></output>
<script>
const suggestions = { team: 'Planning', office: 'Tokyo' };
const edited = new Set();
for (const id of Object.keys(suggestions)) {
document.getElementById(id).oninput = () => edited.add(id);
}
document.querySelector('#apply').onclick = () => {
let count = 0;
for (const [id, value] of Object.entries(suggestions)) {
const input = document.getElementById(id);
if (!edited.has(id) && !input.value) {
input.value = value;
count++;
}
}
document.querySelector('#result').textContent = count + ' field(s) filled';
};
</script>
</body>
</html>Save as index.html and open in a browser to run it locally.