Closed NoSloppy closed 1 year ago
The main gusto here is to prevent invalid entries. Edit -- I just tried it without click-and-type and it's really counterintuitive. If you try to backspace the single digit, you can't get rid of the zero without left arrowing to before the digit, then typing a new value, then deleting the end zero. That's the dance I thought we should avoid with a simple click and type. If you try it, you'll see it's not magic, it makes sense.
https://nosloppy.github.io/ProffieOS-StyleEditor-1/style_editor_BC_V5.html
Open to a better way to prevent NaNs.
Yeah, so the version you linked feels pretty frustrating. It only works if the user knows that they need to hit a number immediately, rather than trying to hit backspace.
I decided to actually try playing with this rather than just reviewing the code itself. By itself, the below prevents you from getting "NaN" text. You could easily hide the spinners with CSS if you wanted.
A += "<input id=ARGSTR_"+N+" type='number' size=6 value=0 onchange='ArgChanged("+N+")' >";
Then if we really need more, these would get us to a solid place.
function ArgSafeguardInt(e) { if (!e.target.value) { var changeEvent = new Event('change'); e.target.value = 0; e.target.dispatchEvent(changeEvent); } }
A += "<input id=ARGSTR_"+N+" type='number' size=6 value=0 onchange='ArgChanged("+N+")' onfocusout='ArgSafeguardInt(event)' >";
Though it's debatable if we want to force the change trigger, as null values do appear to be supported in the string.
A += "<input id=ARGSTR_"+N+" type='number' size=6 value=0 onchange='ArgChanged("+N+")' onfocusout='ArgSafeguardInt(event)' >";
function ArgSafeguardInt(e) { if (!e.target.value) { var changeEvent = new Event('change'); e.target.value = 0; e.target.dispatchEvent(changeEvent); } }
this works well in ArgString. The new function is named ArgSafeguardInt.
So let's make it universal, makingit SafeguardInputs() use this method and be the function to call regardless of which numerical input field it comes from, including Variant, Alt, and any other future number input fields (like upcoming WavLen)
closing and resubmitting cleaner.
IMHO, we should NEVER mess with an input element while it is focused. All of these changes just make it a mess, and while they will be nice in some cases, they will invariably mess it up for some people. I want input element to work the way I expect, not in some magic non-standard way.