tmedwards / sugarcube-2

SugarCube is a free (gratis and libre) story format for Twine/Twee.
https://www.motoslave.net/sugarcube/2/
BSD 2-Clause "Simplified" License
177 stars 41 forks source link

<<numberbox>> uses <input type="text"> #63

Closed gulumige closed 4 years ago

gulumige commented 4 years ago

Currently there's nothing about the macro that keeps the player from entering anything other than a number into the field. Changing the input type to 'number' would be a natural and (from what I can understand) simple solution to this.

tmedwards commented 4 years ago

Using type='number' does not necessarily stop users from entering text that isn't a valid number notation. Some browsers do forbid invalid notation, others merely flag the field's contents as invalid. It also denies the use of any of the newer literal number formats—though, I don't really consider that an issue for <<numberbox>>. The point is that it's not a panacea, you still need to check what you're getting from the player.

That said. The <<numberbox>> macro should have been using something, either type='number' or a pattern, to restrict the field to a valid number format. Thus, I'm marking this as a bug and correcting the oversight.

Thanks for the report.

gulumige commented 4 years ago

Ah, I see. I should use more then one browser to test with in the future.

It does seem like adding text or leaving the field blank using type='number' defaults to 0, not NaN. That could be a worthwhile note to add to the documentation.

hogart commented 4 years ago

On the other hand, on touch screens <input type="number">shows appropriate on-screen keyboard, which is convinient.