How to restrict numeric input range

Hi everyone, I’d like to set a simple limit on the form values. Is there any way to set upper and lower bounds for the addNumber text box, or is adding JavaScript for validation the only option?

This is because dropdown menus are not convenient for teachers to input grades. I found something similar to ->minimum(n) in some parts of the code, but it didn’t work when I tried it.

Hi @AndroidOL Thanks for the question. In order to set an upper bound for a form value by using the ->maximum(n) function.

Here is the an example of a code for your reference:
$row->addNumber(‘enrolmentMin’)->minimum(1)->maximum(999);

Hope that helps!

Thank you for your response. I confirm that it does not work, including the expiration time of 1200 seconds in the system settings. I can set it to 1 second and successfully save it.

I did not find any attributes like min or max in the generated HTML code.

Firefox latest version on Windows and macOS

<input type="text" id="sessionDuration" name="sessionDuration" value="1200" maxlength="50"
    x-validate.required.integer="" data-error-msg="May only contain integer"
    class="w-full rounded-md border py-2 text-gray-900  placeholder:text-gray-500
           focus:ring-1 focus:ring-inset focus:ring-blue-500 sm:text-sm sm:leading-6"
    aria-errormessage="error-msg-sessionDuration" aria-invalid="false">

Hi @AndroidOL Thanks for reporting the issue. After investigation, we have identified it as a bug. It has been fixed in the upcoming Gibbon v29. Cheers!

The latest code is in use; I hope that the error message will include ‘or out of range’.

Thank you for your prompt support!

Reporting an issue: If only the maximum or minimum value is defined, an HTML error occurs. Please use double quotes to properly close the attribute.

The min and max attributes conflict with maxLength. Naturally, we should use max instead of maxLength. However, in scenarios where the maximum value is uncertain, it’s convenient to appropriately limit maxLength to 3.