Let's say I add a textfield field to a user entity.
Cardinality = 1;

After that I see on profile form the following markup wrapped around the textfield:

<div id="field-job-add-more-wrapper"><div class="form-item form-type-textfield form-item-field-job-und-0-value">
  <label for="edit-field-job-und-0-value">Job </label>
 <input type="text" maxlength="255" size="60" value="CEO" name="field_job[und][0][value]" id="edit-field-job-und-0-value" class="text-full form-text">
</div>
</div> 

What seems to be odd.. is this part:

the "-add-more-wrapper" is added to the id in field_multiple_value_form($field, $instance, $langcode, $items, &$form, &$form_state).

Why is this function called??? Is this a bug in field_default_form?

    if (!isset($get_delta) && field_behaviors_widget('multiple values', $instance) == FIELD_BEHAVIOR_DEFAULT) {

      $elements = field_multiple_value_form($field, $instance, $langcode, $items, $form, $form_state);
    }

I cant believe this is the correct behaviour...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

star-szr’s picture

Title: Bug in field_default_form ????? » Single value text fields and textarea widgets are rendered as multiple value widgets
Version: 7.9 » 8.x-dev
Issue tags: -adding fields

I was able to reproduce this behaviour with text fields and textarea widgets only. Drupal 7.10.

  1. Add field with text field or text area widget to user entity or any content type
  2. Set the number of values to 1

The user edit (or node edit) form will show the newly created field wrapped with an ID appended with -add-more-wrapper.

dabblela’s picture

I also have this issue; it breaks things like #states because the ID's don't match what is expected. Could a fix be as simple as changing

if (!isset($get_delta) && field_behaviors_widget('multiple values', $instance) == FIELD_BEHAVIOR_DEFAULT) {

to

if (!isset($get_delta) && field_behaviors_widget('multiple values', $instance) == FIELD_BEHAVIOR_DEFAULT && $field['cardinality'] != 1) {

?

marcingy’s picture

Assigned: Unassigned » marcingy

Just about done with a patch I think there are actually couple of issues
* Add more wrapper is added even when an element does not have the option to add more
* A wrapper is added when there is nothing to wrap.

Just trying to get tests to pass locally at the moment

marcingy’s picture

marcingy’s picture

Status: Active » Needs review

And the patches

netsensei’s picture

Okay. I rerolled the patch so it works with the new WidgetBase class.

There is a problem though. $get_delta is always empty for a single value form element. This causes the form() function to always go for the $this->formMultipleElements() method on line 139 instead of the $this->formSingleElement() on line 120.

The $elements array will be messy if we negate the isset check on line 114 thus borking all tests.

netsensei’s picture

Status: Needs review » Needs work

Setting status.

YesCT’s picture

mgifford’s picture

Assigned: marcingy » Unassigned
Issue summary: View changes

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.

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.

pameeela’s picture

Status: Needs work » Closed (cannot reproduce)
Issue tags: +Bug Smash Initiative
FileSize
43.23 KB
64.45 KB

This works as expected now.

Cardinality = 1:

Cardinality = Unlimited: