As title says.

When you create a Field Collection when a fixed number of items, IE: 3, the embedded widget only shows 2 field collection form items and the user is not able to enter the third one item. Even if the user enters 2 field collection and after saving go to the edit entity page, the third form item is not shown.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

plopesc’s picture

Status: Active » Needs review
FileSize
3.04 KB

Attaching patch that checks hide_blank_items and field cardinality to determine if blank items should be displayed or not.

Regards

jmuzz’s picture

Status: Needs review » Needs work

I would recommend anybody who needs the fix to apply this patch, but it does not seem complete for 2 reasons.

- The description about Hide blank items is not accurate. It does not apply to "any multivalued field" as it states.

- The Hide blank items checkbox appears under the cardinality selector whenever a value other than 1 is chosen. It only makes sense for it to be there if "unlimited" is selected.

TBarina’s picture

Many thanks both to plopesc and jmuzz for this.

plopesc’s picture

Status: Needs work » Needs review
FileSize
3.24 KB
1.18 KB

Patch re-rolled addressing comments in #2

Regards

jmuzz’s picture

Status: Needs review » Postponed (maintainer needs more info)

Thanks for making the changes I requested plopesc.

I'm looking at this again and I'm not sure this is the right approach afterall. Isn't the default behavior for an unlimited cardinality field to start with a single blank item anyway? I don't see what the hide blank items option is supposed to do for them. It's limited cardinality fields that usually present several blank options on the form. Obviously the current behavior of hiding one blank item wrong, but maybe this option is supposed to work on limited cardinality fields and make them work more like unlimited cardinality fields where one blank item is presented with the option to add more.

If the option really does do something useful for unlimited cardinality fields then please explain and I think this can be committed.

plopesc’s picture

Status: Postponed (maintainer needs more info) » Needs review

Hello

Thank you for your review!

This feature is only applied when you're editing an entity containing a field collection. In this case, hides the empty widget that is shown by default in any field type when cardinality is set to unlimited. I think it was done in this way to avoid extra form elements that can mess up the entity form.

But the problem in this issue, as commented in the original post is that this feature does not work properly when it is enabled and cardinality is set to a fixed number. Users are not able to enter the last value. You can reproduce it setting cardinality to 3 and you will see only 2 widgets in the entity form.

If you consider that this feature does not provide any advantage for unlimited cardinality field, we could discuss it and remove it completelly. But as it is now, it breaks the fields behavior when dealing with fixed cardinality fields.

Other option could be move this option from field level to widget level, given that this is a feature that is related to the widget behavior, although, I'm not sure if that's possible because I haven't tested that yet.

Regards

mike.davis’s picture

I agree with plopesc, that there is an issue with the widget not displaying the correct number of fields when a fixed value is set.

With regards to the hide blank items option - I don't think that this applies to limited cardinality. I feel that this would probably be best in a separate issue as there is further discussion needed on this hide blank items option to whether there is any value in making use of this option when using limited cardinality or not.

jmuzz’s picture

The empty widget can mess up an entity form, and there's an issue about getting rid of them entirely. #1788222: Allow "add another" button instead of empty field collection item form when using the embedded widget . I don't think that's what this check box is trying to do. It doesn't seem to do anything to the unlimited cardinality fields. If it did remove the initial blank item that would provide an advantage, but as per the help text on the check box:

"A blank item is always added to any multivalued field's form. If checked, any additional blank items are hidden except of the first item which is always shown."

So the first blank item is always shown, which, for an unlimited cardinality field, is the only blank item until the user hits the add button. The help text only makes sense if it applies to a limited cardinality field, since those are the ones that have additional blank items. I think it would be a useful feature to have if (1) it really did hide all the blank items except for one instead of just removing one and (2) if there was an add button for the limited cardinality fields. A field collection can have many fields and sometimes a user can want to limit the number of field collection items entered without having several blank ones always appearing on the form.

jmuzz’s picture

Status: Needs review » Needs work

I think this issue should be about fixing the behavior of this option on limited cardinality fields and implementing the add button for them. For removing the initial blank item on unlimited cardinality fields there is the other issue.

jmuzz’s picture

Title: 'Hide blank items' setting only should be applied when the field cardinality is set to unlimited » 'Hide blank items' setting doesn't work correctly.
FileSize
2.23 KB

This patch will have it show only a single blank field collection item in a limited cardinality field. By submitting the form multiple times more can be added. A better solution would include the add more button.

jmuzz’s picture

Status: Needs work » Needs review

You are right, I misunderstood what it meant by first blank field collection item. I thought it meant the first blank field collection item every time the form opened, but it really only applies if there are no values in the field collection yet and it actually is hiding that blank item if there are values there already.

  • jmuzz committed bb4c981 on 7.x-1.x authored by plopesc
    Issue #2177963 by plopesc: Hide blank items applies only to unlimited...
jmuzz’s picture

Status: Needs review » Fixed

Thanks plopesc.

plopesc’s picture

Thank you and sorry for the misunderstanding :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.