ILIAS icon indicating copy to clipboard operation
ILIAS copied to clipboard

UI: Numeric Input with stepsize

Open nhaagen opened this issue 7 months ago • 1 comments

Currently, the UI Framework lacks an input for floats. HTML5 specifies the step-attribute for numeric inputs: https://html.spec.whatwg.org/multipage/input.html#attr-input-step

We propose "withStepSize" for \ILIAS\UI\Component\Input\Field\Numeric as described below. This limits the steps to numerics without the "any" option and lets us predict the expected value as int or float.

Consequently, when the step size is given as a floating point number, the field's value will be a float, too, even if it's a whole number. When the stepsize is omited or given as int, decimals will not be allowed or possible.

This will not have any impact on existing code, but will enhance the possibilities of numeric input. A close-by usecase is the scoring of test questions, where points are given as floats.

nhaagen avatar Jun 12 '25 11:06 nhaagen

Hi @nhaagen,

could we just prepend the transformation to the existing one when setting the property to solve the problem that a transformation that was already attached would become invalid?

Kind regards!

klees avatar Jun 23 '25 14:06 klees

Hi @thibsy, hi @Amstutz,

please have a look into this. Please note, that this change will switch types of the contained value, which I opposed in some other case (can't seem to recall which, though). I think it is ok here, because alternatives seems to be worse: For one, I think that everyone using floats invites the devil to her code anyway, so this won't make it worse. On the other hand, creating a dedicated numeric input with fixed point content would make it even more probable that someone actually uses the field. Finally, this only exists because we need it for some case that strongly makes the point that floats are bad (something something points in the T&A), so why bother fixing.

Hope this makes some sense.

Kind regards!

klees avatar Jun 27 '25 17:06 klees

Jour Fixe, 04 AUG 2025: We highly appreciate this suggestion to support the input of floats and accept the PR for trunk.

matthiaskunkel avatar Aug 04 '25 11:08 matthiaskunkel