Dev.to WebDev 🛠 Dev 👁 0 📖 3 min read

Your name on the receipt: autosaving one field without a sign-up

The time card calculator on my site prints a little receipt at the bottom of the page. It shows the week, the hours, the overtime, and the pay. For a long time it had one gap: nowhere on it was the name of the person who

The time card calculator on my site prints a little receipt at the bottom of the page. It shows the week, the hours, the overtime, and the pay. For a long time it had one gap: nowhere on it was the name of the person who worked those hours. A receipt with no name is a piece of paper nobody can file, and that felt like a silly thing to get wrong on a tool built for real workers.

The fix sounds trivial. Add a name field, save it, print it on the receipt. The interesting part is everything I chose not to do while adding it.

There is no sign-up on the site, and I do not want one. An hourly worker checking their pay at the end of a shift should not have to create an account, confirm an email, and remember a password just to see their name on a receipt. So the name had to be saved without any of that. The only honest place for it is the browser itself.

I added a single text input above the time card, labelled simply "Your name". On every keystroke it writes to localStorage under one key, something like tc_name. Nothing goes to a server, because there is no server side to this calculator at all. The whole thing runs in the visitor's browser, and the name field follows the same rule as the hours: nothing ever leaves the device.

On page load the script reads that key back. If a name is there, the field is filled in and the receipt header already carries it. If there is no name, the receipt just says "Time Card" and nobody is nagged about it. The field is optional in every sense. A blank name is a valid state, not an error to fix.

The part that took more thought than I expected was the receipt itself. The receipt is rendered onto a canvas and downloaded as a JPG, so it fits on a phone screen and can be shared or printed. Text on a canvas is not like text in HTML. There is no layout engine to wrap a long name, no CSS to shrink it. I had to measure the name with measureText, and if it was wider than the receipt, trim it down with an ellipsis rather than let it run off the edge. A 40-character name should not break a receipt that otherwise works.

I also had to think about what happens when someone clears everything. The site has a Clear all button on every calculator, and on the time card it wipes the saved browser data too, so a fresh visit starts empty. The name has to go with it. It would be wrong for the hours to vanish while the name hung around. One clear means one clear, the whole lot, name included. That was a deliberate choice, and it is the one users notice most: they press Clear all, reload, and the field is genuinely blank again.

There is a small detail I am quietly pleased with. The name is only ever stored under that one key, and it is only ever read by that one page. It is not copied into any share link. The copy share link feature encodes a whole week of shifts into a URL hash, and I made sure the name stays out of it. A link you paste into a message to your manager should carry the hours, not your name attached to a URL that can be forwarded anywhere.

It is a tiny feature. One field, one key, a few lines of JavaScript. But it is the kind of thing that makes a tool feel finished rather than half-built: the person using it can see themselves on the output, without handing anything over to get there. The time card itself lives on mytimecardcal.com, and the name field is right at the top, waiting, optional, and entirely yours.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.