Steps to reproduce :
(1 to 5 are just there to outline the 'expected' behaviour)
1 - Define a text field - mark it multiple / NOT required
2 - Create a node with 3 values 'foo', 'bar' and 'baz' for the field
3 - Submit
4 - Edit the node, empty the first value 'foo'
5 - Submit : everything OK, the field has the values 'bar' and 'baz', and if you edit the node, you get 'bar' and 'baz' in the first and second textfields (values have shifted)
6 - Now set your field to REQUIRED
7 - Edit the node, empty the first value 'bar'
8 - Submit : you get a 'field is required' error on the first (empty) textfield, yet the field itself should not be considered empty, since you have the 'baz' value in the second textfield

This is content.module stuff - you get the behaviour with number, or noderef with autocomplete fields.

CommentFileSizeAuthor
#13 93447.gif4.38 KBTravisCarden
#13 93447.gif4.16 KBTravisCarden
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

KarenS’s picture

You definitely have found a bug that needs to be swatted. The only thing I would question is the last item where you say you should not get an 'field is required' error if one value is empty. I would interpret required for a multiple value field as requiring that every one be filled out, but maybe that's not the right way to look at it. Sounds like something that needs to be hashed out -- what does 'required' mean for a multiple value field?

yched’s picture

Well, if we had advanced 'multiple' definitions like 'between 3 and 5 values', 'exactly 2', or 'more than 1', it would be different. Then every value could have different semantics.

For the time being, where 'multiple' just means 'possibly several' (and then necessarily 'possibly several of the same thing), i can't think of any other meaning for 'required' than 'not empty'.
'required' can't mean 'every value must be filled out', since 'every' doesn't mean anything...

Let me put it this way :
Say you have a required multiple field
You set its values to 'a ', 'b' and 'c'
Currently, you can edit the node and remove 'c' (last one), but not 'a' or 'b'.
In order to do that, you have to manually shift all the values in the form in order to leave the empty textfields at the end.

Sounds strange, no ?

Egon Bianchet’s picture

Subscribing ...

KarenS’s picture

I hadn't thought too much before about blank fields in the middle, but another question is how do you know if blank fields at the end are fields that are not wanted or not. My original thought had been that you just throw out all blank fields, but if for some reason position is important (not sure why it would be yet, especially since there are no labels or other identifiers for these fields) and there must be blank fields in the middle, then that won't work.

To really solve this issue I think we need to also address the question of how you identify how many multiples you want so we know when to stop adding fields. I think you can make a case that there are times when 'required' should mean that every field is to be filled out, which as you say means we must know how many fields are required, and other times when it might mean only that at least one field needs to be filled out.

I'm inclined to think we must address these two issues together -- a way to indicate how many multiples are needed and a decision about what 'required' means for multiple fields.

yched’s picture

Title: bug with multiple + required fields » multiple + required fields - remove one value -> validation fails

Kind of related bug : http://drupal.org/node/93671

Seems like we do have to be more specific about the definition, 'philosophy' and expected behaviour for multiple fields :-)

yched’s picture

Status: Active » Fixed

fixed in D6

yched’s picture

Status: Fixed » Active

Actually, not fixed :-)
content_set_empty() should take care of stacking non empty deltas at the begining of the $items array.

markus_petrux’s picture

Status: Active » Closed (fixed)

Closing the issue until the spammer comment above is removed.

GuyPaddock’s picture

Version: 6.x-1.x-dev » 6.x-2.6
Status: Closed (fixed) » Active

I'm still seeing this behavior with 6.x-2.6, so I'm re-opening it.

We have a required, multiple-value text field set to take an "Unlimited" number of entries. When entries are removed from the middle of the field (so {"abc", "def", "ghi"} becomes {"abc", "ghi"}) or from the end (so {"abc", "def", "ghi"} becomes {"abc", "def"}), no validation error occurs. However, when the first entry is removed (so {"abc", "def", "ghi"} becomes {"def", "ghi"}), we get "field is required".

Regardless of what the meaning of "required" should be, if it doesn't raise errors for removing other entries, the first field shouldn't be special.

catofcheshir’s picture

I'm stuck with this with date field (required, muptiple values). Only first entry mark with a red '*' , and i can't remove this entry regardless of presence of any more entries.

zazakis’s picture

To really solve this issue I think we need to also address the question of how you identify how many multiples you want so we know when to stop adding fields. I think you can make a case that there are times when 'required' should mean that every field is to be filled out, which as you say means we must know how many fields are required, and other times when it might mean only that at least one field needs to be filled out.video izle I'm inclined to think we must address these two issues together -- a way to indicate how many multiples are needed and a decision about what 'required' means for multiple fields

TravisCarden’s picture

Title: multiple + required fields - remove one value -> validation fails » Deleting the first value in a required, multiple value field fails validation
Version: 6.x-2.6 » 6.x-2.x-dev
Issue tags: +user experience
FileSize
4.16 KB
4.38 KB

another question is how do you know if blank fields at the end are fields that are not wanted or not. My original thought had been that you just throw out all blank fields, but if for some reason position is important (not sure why it would be yet, especially since there are no labels or other identifiers for these fields) and there must be blank fields in the middle, then that won't work. - KarenS

Indeed. I think there is inherent ambiguity in asking a user to delete the content of a field value to signify that they want to remove the whole position at that delta. I don't think the action corresponds to the function. Much more logical, in my mind, would be to delete the value at a position when what you want is a position with an empty value, and create a separate UI element for the (really distinct) function of deleting the whole position from the list—for example, a delete link or button next to each position, as depicted in the attachment. Not only would this eliminate ambiguity, it would make the act of deleting a field value both more "findable" and more "intuitive". (What is the new user left to think when there is a button specifically to "Add another item" but no corresponding button to remove one. It would not be unreasonable to assume, at first glance, that you can add but not remove.)

I also agree that the concept of "required" needs to be more flexible. I should think that the following two options would cover most use cases:

  • Require x values exactly.
  • Require x or more values.
TravisCarden’s picture

I submitted my suggestion as a separate issue at #1120162: Add "delete" links to multivalue field values because I think it has broader implications than simply this issue (even though it would contribute to the solution of this, as well).

TravisCarden’s picture

Title: Deleting the first value in a required, multiple value field fails validation » Deleting the first value in a required, multivalue field fails validation
Project: Content Construction Kit (CCK) » Drupal core
Version: 6.x-2.x-dev » 8.x-dev
Component: content.module » field system

This is still a problem in fields in core.

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.

merauluka’s picture

merauluka’s picture

We are seeing this issue on fields in Drupal 8 also. When a user attempts to remove the first item in a required, multi-value field, the HTML validation fails since the first input in the list has the required="required" attribute set in HTML.

Removing the text from this field is not sufficient to resolve the issue. Nor is reordering the fields. The only workaround we've found so far is to literally add something into the first field and then reorder it as needed. That satisfies the HTML validation and allows Drupal to perform it's form processing.

I think a better solution, and one I've heard requested by a lot of users, is a "remove" button. This is discussed for core here:
https://www.drupal.org/project/drupal/issues/1038316

But there is also a module that appears to add a remove button. The Ajax involved should resolve this issue. Perhaps its logic can be introduced into core?
https://www.drupal.org/project/multiple_fields_remove_button

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

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

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

quietone’s picture

Status: Active » Closed (duplicate)
Issue tags: +Bug Smash Initiative

This is the same problem that is being solved in #1038316: Allow for deletion of a single value of a multiple value field

While this is the earlier issue the other one has patches and more discussion. Closing this as a duplicate and moving credit.

brad.bulger’s picture

The issue that this is marked as a duplicate of is not really this same problem. It is about a UI widget to let users remove items from a multiple value field. I added a new issue #3344082: Improve required validation of multiple value fields that is about improving 'required' validation of multiple value fields, to consider the field as a whole instead of only delta 0 in whatever position it might be.