Problem/Motivation

When creating a field the form validation does not check field values with the default value. For an integer one can save a default value that is lower than the minimum value. The form validation should prevent this combination, but allows the field to be saved.

This error happens only when the fields are being created, on the editing form the values are validated as expected.
validation not working on creation
Validation working on editing form.
validation works on editing field

Steps to reproduce

  1. create an integer field
  2. set a default of say 6
  3. set the minimum to 10
  4. The from is saved without error

Proposed resolution

Add validation on the element returned by formElement method.

Remaining tasks

none

User interface changes

none

API changes

none

Data model changes

none

Release notes snippet

none

Issue fork drupal-2907520

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

joachim created an issue. See original summary.

joachim’s picture

Title: Field UI doesn't validate a field's default value » Field UI doesn't validate a field's default value on create

Editing it later works as expected.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Issue summary: View changes
Issue tags: +Bug Smash Initiative

Tested on 9.3.x, standard install and the problem still exists.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

lauriii’s picture

Issue tags: +Field UX
joaopauloc.dev’s picture

Assigned: Unassigned » joaopauloc.dev
joaopauloc.dev’s picture

Issue summary: View changes

joaopauloc.dev’s picture

Issue summary: View changes
StatusFileSize
new1.47 MB
new1.65 MB
joaopauloc.dev’s picture

Assigned: joaopauloc.dev » Unassigned
Status: Active » Needs review
smustgrave’s picture

Status: Needs review » Needs work

I applied the MR and followed the steps in the issue summary
Created a Number(Integer)
Added 10 to the minimum
Added 6 as the default

I can save still.

joaopauloc.dev’s picture

Status: Needs work » Needs review

Thanks for the review @smustgrave, issues are fixed.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Confirmed the issue I was seeing in #21 has been fixed.

lauriii’s picture

Status: Reviewed & tested by the community » Needs work

Looks like the new test failed after the rebase 😔

akhil babu’s picture

\Drupal\Core\Field\Plugin\Field\FieldType\NumericItemBase::getConstraints calls Drupal\Core\Field\FieldItemBase::getSettings and Drupal\Core\Field\Plugin\Field\FieldWidget\NumberWidget::formElement calls Drupal\Core\Field\WidgetBase::getFieldSettings to check for min and max values while saving the number field. But both getSettings and getFieldSettings return NULL for min and max values when creating number field. This is why validation is not working.

akhil babu’s picture

This issue seems to be fixed in drupal 11(11.x-dev branch).
\Drupal\Core\Field\Plugin\Field\FieldType\NumericItemBase::getConstraints as Drupal\Core\Field\FieldItemBase::getSettings correctly returns min and max values when creating the field.

akhil babu’s picture

Status: Needs work » Needs review

Review if error is reproducible in 11.x-dev

akhil babu’s picture

StatusFileSize
new1.56 MB

akhil babu’s picture

smustgrave’s picture

Status: Needs review » Needs work

Feedback from MR still needs to be addressed.

joaopauloc.dev’s picture

Status: Needs work » Closed (cannot reproduce)
StatusFileSize
new4.6 MB

This issue was fixed on the current 11-x.
Follow the test below.
issues test fixed
Not sure if I'm updating correctly but we don't need to fix the one anymore.
Thanks.