-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
number.module is enforcing a maximum value even if one is not specified #6137
Comments
Looking at the "blame" history, it looks like this was added to control the size of the widget. According to Mozilla, number inputs don't accept the Solving this by removing the #max attribute without affecting the look of the widget will be tricky - adding css to Basis is one way to go, but that would leave out all contrib themes. |
I understand your concern. I'm not sure what kind of work-around would be needed. However, enforcing a maximum value where one may not be required could become a serious issue if the developer was not aware of this. As of right now, every number field has a maximum value My proposal is that this flaw needs to be rectified and once it that is in place, an hook_update() needs to process all existing number fields within a site and define a max of At the very least, the field definition's description needs to be updated to indicate to the dfeveloper exactly what it is doing behind the scenes. |
@rbargerhuff I agree this needs to be fixed. I was just pointing out things to keep in mind when we are fixing - it seems you gave this already some thought. Would you be able to submit a PR? |
Thanks for the background research @argiepiano. I couldn't find an original issue other than the pull request, it might have been so early in Backdrop development we didn't track everything with issues yet. The original PR is here: backdrop/backdrop#247 I agree that we shouldn't be using Here's a field with a max of 3, which you'd think would display only large enough for 1 character, but it displays enough field for a much larger number: |
I was looking into this issue yesterday with @rbargerhuff and reached the same conclusion as @quicksketch. I couldn't get the size of the number field to change, even without the Is it already being controlled by the default Backdrop theme(s)? I was testing with Seven and only found |
Sorry I can't. I recently finished a Backdrop Core PR involving Layouts and new features... I just do not have the time to submit a new PR due to time constraints with getting Backdrop deployed to our production websites and sticking to our rollout schedule. |
I guess, this has partly been discussed before in #4751 There will always be a limit, just because of the database - the highest value, that can be saved. |
Yes, there will be always a limit, even if that is the database limit. The description of that form element should be changed.
|
Both @indigoxela and @kiamlaluno are correct that there will always be a limit enforced by the database. Here's the thing I just realized - while Backdrop is enforcing a default maximum limit on number fields, it doesn't enforce a default minimum limit on those fields. So if you create a number field, leave the minimum limit blank, then try to populate that field with a number lower than what the database will accept, the site will return a database error. My suggestion is that we let these fields accept the lowest/highest number the database will allow when a minimum/maximum is not specified. Here's how we can handle it for the different number types:
I submitted a PR containing the default ranges above, including the theoretical range on float values. Let me know what you all think. |
@smaiorana many thanks for providing a PR. 🙏 So, if I get it right, your suggestion is to always display min/max in the field widget? The previous PR just prevented admins to set an unusable limit. Not sure, if that's ideal if it comes to user experience... Needs some testing with common use-cases. |
Thanks for contributing @smaiorana 🙏🏼 I will need to have a closer look and do some research, but for now I would like to leave these 2 comments here:
|
...the trick mentioned here might be of help: https://stackoverflow.com/questions/2679064/in-sql-how-do-i-get-the-maximum-value-for-an-integer So we might be able to use that to set some global constants with respect to what is supported by MySQL + then take into account what the current version of PHP supports handling. Having said the above, we need to consider that reaching these limits is still theoretical and would apply to edge cases (sites that use maths?). As long as our help text mentions what the min/max supported values can be, I think that we're good. |
@klonos I think the theoretical limits are for floating point numbers only. Correct me if I'm wrong, but I believe MySQL/MariaDB always has a standard range of -2147483648 to 2147483647 on the signed INT data type (which is what Backdrop's integer fields use). I think it's generally safe to hardcode those. It's already hardcoded into number.module when you save the settings on a number field:
But for floating point numbers, I haven't been able to find a way to gauge limits on those, though the likelihood that someone would reach a number like 3.402823466E+38 I think puts in in the category of edge cases like you said.
That looks like a holdover from Drupal 7. I can change the field type in my PR if you'd like.
Are you suggesting something like this: "The maximum value that should be allowed in this field. Leave blank for 2,147,483,647 (the maximum value that can be saved in the database)." |
I think that suggestion for wording makes sense. |
I just run into this problem. I tested the PR, and it works fine for me. |
Thanks folks! I wasn't sure about the extremely high values set for float, but in testing this didn't seem to have any negative impact and it seems like a good safety measure. With the approval of multiple people, I went ahead and merged backdrop/backdrop#4483 into 1.x and 1.25.x. Thanks @smaiorana for your work and @rbargerhuff for filing the issue! backdrop/backdrop@a8cb694 by @smaiorana, @rbargerhuff, @argiepiano, @indigoxela, @kiamlaluno, @klonos, @yorkshire-pudding, @robertgarrigos, and @quicksketch. |
Description of the bug
This issue/bug concerns the
number.module
within Backdrop Core. When defining aNumber (integer)
field, if states that if a maximum value is not specified for the field, then there will not be a maximum value set for the field. Below is the help text for theMaximum
setting associated with theNumber
field."The maximum value that should be allowed in this field. Leave blank for no maximum."
Here is the code that is enforcing the maximum when one is not required:
Expected Behavior
Honor not having a maximum value defined on a
Number (integer)
field.Additional information
The text was updated successfully, but these errors were encountered: