Problem statement
A profile page that starts out already filled in and only lets the person save once they have actually changed something. The Save button stays off while the form matches what was there on load, and turns back off the moment things go back to matching. Reset snaps everything back to how it was, and the browser only asks "are you sure?" when there are still unsaved changes.
Demo
The page, styles, the pre-filled fields, message spots, Save button, Reset button and success banner are already scaffolded and wired. Only the isDirty function in src/js/dirty.ts, the validate function in src/js/validation.ts, and the renderValues, renderFieldError, renderSaveEnabled and renderSavedFlash functions in src/js/render.ts are missing — implement them so every test passes. Do not edit any other file.
What to implement
- On load, show the three starting values in the three fields, keep the Save button switched off, keep the success banner hidden and keep every reminder spot next to a field empty.
- When the person changes any field so it no longer matches the starting value, turn the Save button on; when they change it back so it matches again, turn it off.
- Hide the success banner as soon as the person starts editing again, so it never lingers next to changes that have not been saved.
- When the person clicks Save and something is wrong, show a short reminder next to any field with a problem and keep the Save button on.
- When the person clicks Save and everything is fine, remember these values as the new starting point, turn the Save button off, clear every reminder and show the success banner.
- When the person clicks Reset, put every field back to the current starting values, wipe every reminder, hide the success banner and turn the Save button off.
- While the form has unsaved changes, make the browser show its built-in "leave this page?" prompt if the person tries to navigate away, and let them leave silently when there are no unsaved changes.
- Everything shown must come from the starting values you were given and the current values on the page — nothing should be hardcoded.
