Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I have an Entity Collection field for storing contact details for a person. The Firstname and Surname fields are required, while the address, phone, etc. are optional.
I'm trying to add this field to a new content type but cannot submit the form as I apparently need to enter a Firstname and Surname for the default values (since they're required). See attached screenshot to see what I mean.
The default value section should ignore the required fields as far as I'm concerned...
Comments
Comment #1
BWPanda CreditAttribution: BWPanda commentedBTW, I'm not sure if this is related to #1239946: Embedded field collection items with a default value result in new items on save or not...
That issue seems to deal with another problem relating to required fields, and when I tried the patch there it didn't do anything to fix this problem on the field settings form.
Comment #2
charlie-s CreditAttribution: charlie-s commentedI second this request. Just because the field is required doesn't mean a default value should be supplied.
Comment #3
Fidelix CreditAttribution: Fidelix commentedcsdco, I doubt this is on purpose.
This is probably a validation problem that Field_collection needs to bypass.
But yes, this should be implemented since it prevents you from using the module on some cases, unless you use some workarounds.
For now, you can set the name/surname fields to not-required, then save your form, then set the fields to required again.
That's how I'm doing it.
Comment #4
klonos@BWPanda: Hey Peter, I'm sure you can come up with a less vague issue title that better describes the problem. You won't get any attention if you leave it as it is now. Something like a phrase that includes verbs too perhaps? If what I came up with is not ok with you, simply change it as you see fit ;)
Comment #5
Fidelix CreditAttribution: Fidelix commentedHow about this?
Comment #6
klonos...perfect ;)
Comment #7
John Pitcairn CreditAttribution: John Pitcairn commentedThis one is biting me too. I have required fields, but if I set a default value my users will just accept those defaults without thinking about it. Not good.
(a bit later)
If you don't need to configure anything in the collection instance, you can just exit the collection-edit form without submitting, and your required fields will not have default values set. Coincidentally, this also avoids the issue in #1239946: Embedded field collection items with a default value result in new items on save.
But that's a small subset of cases.
Comment #8
akamaus CreditAttribution: akamaus commentedI made a somewhat dirty fix, it works for me. The idea is to enumerate the fields inside the collection on the form build and to remove #required attributes. I do this only for form titled 'Default value'. I didn't find a better way to differentiate between the configuration and ordinal forms.
Comment #9
akamaus CreditAttribution: akamaus commentedthe original idea of merging tweaked form array didn't work.
Comment #10
chingis CreditAttribution: chingis commentedpatch #9 didn't worked for me
Comment #11
akamaus CreditAttribution: akamaus commentedcan you elaborate a bit more? What's your use case? Do any errors or warnings or notices appear after patching?
Comment #12
akamaus CreditAttribution: akamaus commentedAfter upgrade to 7.15 I found what patch #9 stopped working. I attach fixed version here.
Comment #13
gmclelland CreditAttribution: gmclelland commentedFYI... Don't believe the patch in #12 applies to the latest dev.
Comment #14
SpadXIII CreditAttribution: SpadXIII commentedI just (manually) applied patch in #12 to 7.x-1.0-beta4, which seems to just remove the validation-issue.
Saving the configuration of the field in the content type now works.
Though, when adding new content the field shows 2 field-collection rows, instead of just 1.Somehow it saved the empty default values as a new row?edit: never mind my brainfart. That was me not seeing the 'default value' in a certain field.. /doh
Comment #15
kscheirerI was not able to reproduce this bug against the latest dev version, 7.x-1.0-beta4+14-dev. Please try upgrading to this version first, and then posting the steps to recreate the bug.
Comment #16
mstrelan CreditAttribution: mstrelan commentedI have the latest dev release and am experiencing this issue also. Steps below.
PS. I haven't confirmed this but it might only be an issue when there is a boolean field set to "single on/off checkbox"
Comment #17
presleyd CreditAttribution: presleyd commentedThe steps listed in #16 apply to 7.x-1.0-beta5 also. In fact there are two 'Default value' fieldsets on the form. One of them correctly tells you to go to the individual field to set a default value and the other one which shows you a sample of each field and forces you to set a default for required fields.
The work around is to make those fields not required while editing the Field Collection and then marking them required again later but that "= teh suck".
Comment #18
presleyd CreditAttribution: presleyd commentedThis only seems to happen with a Field Collection Table widget type. Moving this issue.
Comment #19
BWPanda CreditAttribution: BWPanda commentedHere's a patch that disables default values for the Field Collection Table widget. It now works that same as Field Collection in that it tells you to set default values for each of the fields in the field collection directly.
Comment #20
presleyd CreditAttribution: presleyd commented#19 works for me.