Repro steps:
Add a list(integer) field to an entity.
Set the valid values to something like:

  • 0|zero (one key must be 0)
  • 1|one

Set the field to Required
Do not set a default
Visit the form to create an entity of the type
Enter all other required fields
Hit save/submit

The form will be accepted.

CommentFileSizeAuthor
#3 1475738.patch793 bytesdamiankloip

Comments

webbykat’s picture

I tested this out and reproduced the problem -- it saved without giving me the correct "field is required" type message. I followed the steps above, written out again for thoroughness:

  • I added a list (integer) field to a content type (in my case, Article).
  • I set 0|zero and 1|one as the options.
  • I set the field to be required.
  • I didn't set a default value.
  • I created a new article and saved without selecting an option.

I checked for this bug in Drupal 8 and didn't find it. It appears to be a problem only for D7.

damiankloip’s picture

I think there is a missing step to reproduce this, which is that the field widget should be 'checkboxes/radio buttons' as this works as expected for select lists.

damiankloip’s picture

Status: Active » Needs review
StatusFileSize
new793 bytes

Maybe adding a little bit extra in the option widget validation would do the trick? I'm not not how/if this will play well with all other fields.

dcam’s picture

Issue summary: View changes
Status: Needs review » Closed (cannot reproduce)

I can't reproduce this issue any longer in version 7.36. I'm pretty sure this was fixed in form.inc's _form_validate() at some point. See this comment relating to validation of required elements:

      // A simple call to empty() will not cut it here as some fields, like
      // checkboxes, can return a valid value of '0'. Instead, check the
      // length if it's a string, and the item count if it's an array.
      // An unchecked checkbox has a #value of integer 0, different than string
      // '0', which could be a valid value.