Skip to content

Commit

Permalink
Forms: re-enable max and min limits for Number fields(#1915)
Browse files Browse the repository at this point in the history
Co-authored-by: Ali Alam <[email protected]>
  • Loading branch information
2 people authored and SKuipers committed Mar 6, 2025
1 parent 460701b commit a3a8bb3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ v29.0.00

Bug Fixes
System: fixed issue with search terms containing a : full colon (special character)
System: Add max and min limits to form values
Sidebar: fixed localization of Roles menu items.
Activities: fixed activity missing from the timetable if it doesn't have a category
Activities: fixed missing registration button for parents on View Activities page
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/Input/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,6 @@ protected function setValidation()
*/
protected function getElement()
{
return Component::render(Number::class, $this->getAttributeArray() + []);
return Component::render(Number::class, $this->getAttributeArray() + ["min" => $this->min, "max" => $this->max]);
}
}
5 changes: 3 additions & 2 deletions src/Forms/Input/Number.template.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<div class="flex-grow relative flex" >
<input type="text" <?= $attributes; ?>
class="w-full rounded-md border py-2 text-gray-900 placeholder:text-gray-500
<input type="number" <?= $attributes; ?>
min=<?= $min; ?> max=<?= $max; ?>
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" />
</div>

4 comments on commit a3a8bb3

@AndroidOL
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Work. It runs perfectly, but there are only two error messages: "Only integers allowed" and "Only numbers allowed." I believe it should display an error message indicating that the input number is out of range.

@AndroidOL
Copy link

@AndroidOL AndroidOL commented on a3a8bb3 Mar 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

case 'numericality':

                case 'numericality':
                    $onlyInteger = $params['onlyInteger'] ?? false;
                    $validations[] = $onlyInteger ? 'integer' : 'number';
                    $message = $onlyInteger 
                        ? __('May contain only whole numbers')
                        : __('May contain only numbers');

@AndroidOL
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

case 'numericality':
    $onlyInteger = $params['onlyInteger'] ?? false;
    $validations[] = $onlyInteger ? 'integer' : 'number';
    $message = $onlyInteger 
        ? __('May contain only whole numbers')
        : __('May contain only numbers');
    if (isset($params['minimum']) || isset($params['maximum'])) {
        $message .= ' ' . __('or out of range');
    }
    break;

@AndroidOL
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SKuipers Is this request feasible? Thank you.

Please sign in to comment.