Found this bug in D7 and verified this is still in D8 code:
* Create required Bool field with radio options widget
* Have #access=false and submit
(maybe this bug is also triggered when selecting 0 value)
* Form error: "!name is required"

Options module checks:

if ($element['#required'] && $element['#value'] == '_none') {
    form_error($element, t('!name field is required.', array('!name' => $element['#title'])));
  }

Bitchy PHP's opinion is thus:

php > print 1 == '_none';
php > print 0 == '_none';
1
php > print 0 === '_none';

So we need to change this check to ===
* D7: options_field_widget_validate()
* D8: OptionsWidgetBase::validateElement()

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

geek-merlin’s picture

geek-merlin’s picture

Title: Options widget counts 0 or NULL as "none selected" » Options widget counts 0 as "none selected"
Version: 8.x-dev » 7.x-dev
Status: Active » Needs review
FileSize
1.1 KB

Applied said fix and the bug is fixed here.

Patch flying in for 7.x

geek-merlin’s picture

Version: 7.x-dev » 8.x-dev
FileSize
1.18 KB

And 8.x...

SpadXIII’s picture

Just a thought: why would an element be validated while it has an #access = false ?
The function 'options_field_widget_validate' (d7) is the #element_validate of the form field.

Should there be an access-check here or higher up the chain: should an element without access be validated?
I'm leaning towards the first; add "$element['#access'] &&" in the if-statement. There might be a custom element_validate that needs to check other things.

mgifford queued 3: drupal-D8-2287743-3.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 3: drupal-D8-2287743-3.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.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.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.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.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.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.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.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.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should 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.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should 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.

anrikun’s picture

Bumping this.
Patch at #2 for D7 works.

anrikun’s picture

Version: 8.6.x-dev » 7.x-dev
Status: Needs work » Needs review

Drupal 8 has changed a lot since patch at #3 and AFAIK this bug is not present in current D8 any more.
Thus turning version to 7.x-dev

anrikun’s picture

Status: Needs review » Closed (duplicate)
Related issues: +#2895721: Options field widget validation fails when integer is provided