Skip to content

Conversation

@Duarte-22
Copy link

Checklist before requesting a review

Please delete options that are not relevant.

  • I have read the CONTRIBUTING document.
  • I have performed a self-review of my code.

Description

  • It fixes Add decimals option to numberField #21861, adding a decimal options, so a field can have a different number of decimals from the default.
  • This adds a simple check on the Number Input if it has a decimals option, it adds its value to "Html::formatNumber" to show the specific number of decimals. This is useful when a field requires numerous decimals compared to other fields.

Screenshots (if appropriate):

image image

{# Only format number if not a whole number #}
{% set value = call('Html::formatNumber', [value, true]) %}
{% if options.decimals is defined %}
{% set value = call('Html::formatNumber', [value, true, options.decimals]) %}
Copy link
Contributor

Choose a reason for hiding this comment

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

Using formatting on a value going to an input seems odd to me. Wasn't there a bug recently related to using formatted numbers in inputs in another place (Infocom maybe)?

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, I'm not aware of this bug. The Html::formatNumber already had the option to add decimals control for the display of numbers, the idea was to use it to extend some input fields, in my case the Latitude and Longitude, without needing to change on other fields.
The best idea, in my opinion, mas to change based on the step, but that looked a little more complex. If you fill like this is a better solution, I can try it.

Copy link
Contributor

Choose a reason for hiding this comment

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

My opinion is that our format functions should be used when displaying the value itself as text. In the context of inputs, it is up to the browser to format the displayed value based on the locale. So, beyond specifying the min, max and step, I don't think there is much other control over it without a more complicated solution like using a text field and custom conversions instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add decimals option to numberField

3 participants