Problem/Motivation

Float field does not allow minimum value to be a decimal value.

Proposed resolution

Minimum and maximum value on a float field should allow decimal values.

Remaining tasks

Get branch maintainer approval.

User interface changes

None

API changes

None

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug because float values shouldn't be delimited by integer values
Disruption Non disruptive.

Comments

berdir’s picture

The UI or storage?

amitsedaiz’s picture

The issue occurs at the field UI level. It happens when creating a new field (Decimal or float) or editing the field ui settings. The problem happens for Default Value, Min and Max Value.

Also, when creating the field for the first time, the system does not validate if the default value is greater than the max value specified in the field ui settings. It does however validate during editing the field ui settings,

amitsedaiz’s picture

Status: Active » Needs review
Issue tags: +#SprintWeekend2015
StatusFileSize
new1.06 KB

Hi,

I have created a patch. It works for me. Kindly review.

penyaskito’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests, +Needs issue summary update

Thanks for working on this!

IMHO we should do this by overriding the method in FieldType/DecimalItem and FieldType/FloatItem instead of adding an if-case.
Also, this would need tests and an issue summary update.

yesct’s picture

Issue tags: -#SprintWeekend2015 +SprintWeekend2015

@amitsedaiz
Thank you for working on this issue.

We should all try and use the same sprint tag. According to https://groups.drupal.org/node/447258 it should be SprintWeekend2015 with no #.

gloob’s picture

Starting to work on this issue.

gloob’s picture

Status: Needs work » Needs review
StatusFileSize
new2.02 KB
new2.54 KB

Moved logic for the redefinition of the form settings into FieldType/DecimalItem and FieldType/FloatItem.

I didn't find current tests for Fieldtypes in the code so I didn't add a new test case, probably it should be a complete test definition that should be covered in a new ticket?

Find some problems in the way we are representing decimal points in the UI, I'll create a new ticket for that.

yesct’s picture

@gloob
We can make a new issue to add more complete test coverage, but the bug for just this one part needs to have a test in *this* issue.

Try writing a test and stick it somewhere, reviews of the test will help improve any first try you do at it. :)

penyaskito’s picture

Status: Needs review » Needs work

Needs work per #8.

geertvd’s picture

geertvd’s picture

Status: Needs work » Needs review

The last submitted patch, 10: drupal8-float-forced-integer-2408227-10-test.patch, failed testing.

penyaskito’s picture

Issue tags: -Needs tests

This looks awesome! Thanks @geertvd for your contribution!

Next time you should try to upload an interdiff too.

Can we get an update to the issue summary?

geertvd’s picture

Issue summary: View changes

Didn't think an interdiff was necessary since I just added the test.

penyaskito’s picture

My fault then, sorry!

penyaskito’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs issue summary update

Added beta evaluation template, IMHO we are good to go!

penyaskito’s picture

Issue summary: View changes
alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/field/src/Tests/Number/NumberFieldTest.php
@@ -459,4 +459,38 @@ function testNumberFormatter() {
+    $this->assertNoRaw(t('%name is not a valid number.', array('%name' => t('Minimum'))), 'Saved decimal value as minimal value on a float field');
...
+    $this->assertNoRaw(t('%name is not a valid number.', array('%name' => t('Minimum'))), 'Saved integer value as minimal value on a float field');

This is a negative test and therefore very fragile - it should at least be accompanied by a positive assertion that what we expected to occur has occurred.

geertvd’s picture

Status: Needs work » Needs review
StatusFileSize
new1.96 KB
new2.87 KB
new4.89 KB

Something like this should cover that.

The last submitted patch, 19: drupal8-float-forced-integer-2408227-19-test.patch, failed testing.

penyaskito’s picture

Status: Needs review » Reviewed & tested by the community

#18 was taken care of and looks good.

gloob’s picture

This issue fix two problems at once. The float field and decimal field. I would say we need additional test also for the decimal field.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Nice catch @gloob. Let's add a test for decimal too.

geertvd’s picture

Added the decimal field test and a helper function to make it all a bit more readable

geertvd’s picture

Status: Needs work » Needs review

The last submitted patch, 24: drupal8-float-forced-integer-2408227-24-tests.patch, failed testing.

gloob’s picture

Status: Needs review » Reviewed & tested by the community

Looks good for me. Great job @geertvd! :-)

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/field/src/Tests/Number/NumberFieldTest.php
    @@ -477,28 +478,52 @@ function testCreateNumberFloatField() {
    +    // Set the minimum value to an decimal value.
    +    $this->setMinimumValue($field_type, $field_name, 0.1);
    

    Perhaps this should be a float like 0.0001 - something that would not work for a decimal field.

  2. +++ b/core/modules/field/src/Tests/Number/NumberFieldTest.php
    @@ -477,28 +478,52 @@ function testCreateNumberFloatField() {
    +  /**
    +   * Helper function to set the minimum value of a field.
    +   */
    +  function setMinimumValue($field_type, $field_name, $minimum_value) {
    

    If this is called assertSetMinimumValue() simpletest will report a more useful line number..

  3. +++ b/core/modules/field/src/Tests/Number/NumberFieldTest.php
    @@ -477,28 +478,52 @@ function testCreateNumberFloatField() {
         $this->drupalPostForm($field_configuration_url, $edit, t('Save settings'));
         // Check if an error message is shown.
    -    $this->assertNoRaw(t('%name is not a valid number.', array('%name' => t('Minimum'))), 'Saved integer value as minimal value on a float field');
    +    $this->assertNoRaw(t('%name is not a valid number.', array('%name' => t('Minimum'))), 'Saved ' . gettype($minimum_value) .'  value as minimal value on a ' . $field_type . ' field');
    

    Let's also assert some form of success message.

geertvd’s picture

Status: Needs work » Needs review
StatusFileSize
new3.99 KB
new3.65 KB
new5.67 KB

The last submitted patch, 29: drupal8-float-forced-integer-2408227-29-tests.patch, failed testing.

pjbaert’s picture

Status: Needs review » Reviewed & tested by the community

Changes suggested by @alexpott are implemented

  • alexpott committed 0d15b2b on 8.0.x
    Issue #2408227 by geertvd, gloob, amitsedaiz: When creating a float...
alexpott’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Needs tests

This issue is a normal bug fix, and doesn't include any disruptive changes, so it is allowed per https://www.drupal.org/core/beta-changes. Committed 0d15b2b and pushed to 8.0.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.