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()
Comments
Comment #1
geek-merlinComment #2
geek-merlinApplied said fix and the bug is fixed here.
Patch flying in for 7.x
Comment #3
geek-merlinAnd 8.x...
Comment #4
spadxiii commentedJust 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.
Comment #13
anrikun commentedBumping this.
Patch at #2 for D7 works.
Comment #14
anrikun commentedDrupal 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
Comment #15
anrikun commentedClosing in favour of #2895721: Options field widget validation fails when integer is provided that includes tests.