tmedwards / sugarcube-3

SugarCube is a free (gratis and libre) story format for Twine/Twee.
17 stars 1 forks source link

Improvement suggestions for <<numberbox>> #40

Open BawdyInkSlinger opened 3 years ago

BawdyInkSlinger commented 3 years ago

I have some suggestions for improvements to this macro:

tmedwards commented 3 years ago

I'm going to assume that you're referring to the <<numberbox>> macro that was first added to the standard library in v.2.32.0 and updated in v.2.33.0. I'll be referring to the latest public version.

I have some suggestions for improvements to this macro:

Considering that the macro's actual UI widget is an <input type="number"> element, most of your suggestions are probably going to need to be filed with (a) the standards groups and/or (b) the browser manufacturers. If I don't specifically reply to something below, then that's the case—or I consider it such, anyway.

Additionally. As is often the case, the <input type="number"> UI is not consistent across browsers, so some of your complaints are not cross-browser—in particular, Gecko and Blink have very different behavior here. E.g., Chrome does not allow any letters to be entered—aside from the scientific notation e.

  • It considers a decimal point to be an error unless it's .0 -- I think these should be configurable validation settings. Sometimes you want to real numbers, sometimes you only want integers.
  • It doesn't let you specify a valid range -- I think more often than not, there is a valid range and an invalid range. It would be nice if the macro allowed you to specify it. You should not be able to use numbers outside of this range.

These are possible to address in SugarCube, but may not be in v2 due to argument list issues. Additionally, some, like range, can be checked by user code post-input.

  • It saves a string into the variable, making it inconvenient to implement custom range validation. -- I think the variable should be a number type

I'm unsure what you think you're seeing, but it only stores numbers within the receiver variable. Beyond that, no browser that I know of writes non-numbers to the field value of an <input type="number">, so <<numberbox>> never even sees non-numbers to begin with.

tmedwards commented 3 years ago

Browsers (chiefly Firefox ) should no longer flag decimal numbers as invalid in the next release.

tmedwards commented 3 years ago

With the recent inputmode change (commit tmedwards/sugarcube-2@a9984f94ad71ece027e66a619206c7d2f391e1a6), I've done about as much as I can do for <<numberbox>> in v2 without introducing breaking changes. Thus, I'm going to move this issue over to the v3 repo.