- 🇺🇸United States sidgrafix
+1 (used patch #15) Drupal 10.3.2 and inline_entity_form 8.x-1.0-rc17
Saved me after days of trying to get a field that should NOT be required when the field is part of a media entity using the inline entity form as an option on the content type edit/add form. Specifically when media entity type reference field "video" is used if a video wasn't uploaded a name shouldn't be required. Which cause other issues (as a workaround even tried) including a name when no video file was uploaded which then caused the media entity to be created and it shouldn't have been.
...Frustrating to say the least and the cause of a wicked headache until I finally realized inline_entity_form was causing the overall issue and finally stumbled onto this thread.
(but this is definitely needed) - thought I was going to have to dive into declaring an inline entity form controller for media to get it to work right after having tried every conceivable hook and callback to try and alter the fields #required state to FALSE (almost went with disabling default validation) for the entire node form on submit and validate it all in a callback - so glad I found this instead!Also tried inline_media_form but that made things worse plus had to download it and add drupal 10 in it's info file just to try it.
- 🇮🇳India santhosh@21
#35 patch didn't worked for me as the empty media reference is getting created.
- First commit to issue fork.
- Merge request !136Required fields make an optional IEF (erroneously) required → (Open) created by saidatom
- Status changed to Needs review
5 months ago 5:26pm 8 May 2025 The 3.x branch (#35) version of this patch is causing a POST 500 Internal Server Error having to do with Ajax. The error occurs when you try to add a new entity (adding an existing entity works as expected).
Here's the steps to reproduce the error:
Create a new content type and add a new field "Reference" field. Select "Content" for the entity reference type and configure the field to accept an existing content type. Next select the "Manage form display" tab and edit the new reference field to use "Inline entity form - Complex" and "Allow users to add existing nodes". Create a new page using the new content type and for the new entity reference field, click the "Add existing node" button. Use type-ahead to select an existing node and click the "Add node" button. Nothing happens and errors are displayed in the browser console.dgilbert → changed the visibility of the branch 3099844-required-fields-make to hidden.
dgilbert → changed the visibility of the branch 3099844-required-fields-make to hidden.
dgilbert → changed the visibility of the branch 3099844-required-fields-make to active.
I believe this will fix the bug (#41) in the #35 patch for 3.x branch.
- 🇩🇪Germany Anybody Porta Westfalica
I believe this is still a very relevant issue for 3.x
- 🇩🇪Germany Anybody Porta Westfalica
@dgilbert could you maybe incorporate your path into the MR on 3.x for push things forward here cleanly?
We shouldn't use patches anymore... - 🇩🇪Germany Anybody Porta Westfalica
I think #23 still is valid:
I think it still needs work to maybe address browser validation, or deal with field with default values being added.
Best would be to have tests for such cases to ensure it works as expected. Logically I think we're not that far from the finish line...
- 🇩🇪Germany Grevil
The problem with this approach that this doesn't fix the client side validation through HTML 5, but only the server side validation.
A simpler approach for this would be, to simply not show any "empty" field item. So the user has to always press "Add entity" first.
- Merge request !143Issue #3099844: Required fields inside referenced entity make an optional IEF (erroneously) required (alternative approach) → (Open) created by Grevil
- 🇩🇪Germany Grevil
Created an MR with a different approach.
I added a new setting called "do_not_show_initial_empty_item", which basically doesn't show the initial empty inline entity form until the "add" button is pressed.
This is not perfect yet (see https://git.drupalcode.org/project/inline_entity_form/-/merge_requests/1...) but this way we don't have to change the validation logic at all server nor client side.
- 🇩🇪Germany Anybody Porta Westfalica
I guess this should indeed be fixed upstream in 🐛 Fields with unlimited cardinality show 1 extra input field Needs work , afterwards we should ensure that it works as expected and the default is "0" for IEF.
- 🇩🇪Germany Grevil
Alright, the alternative approach of not showing the initial empty item is finished now. Although it is a bit hacky. It extends the already existing hack introduced in #2664626: Add another item does NOT work the first time it is clicked on simple widget → and partially overwrites WidgetBase core functionality.
So although this approach is theoretically working, it would be better to have a proper fix through 🐛 Fields with unlimited cardinality show 1 extra input field Needs work , close this issue and introduce an issue which cleans up the old hack from #2664626: Add another item does NOT work the first time it is clicked on simple widget → and forces "cardinality_display" to be 0.
- 🇩🇪Germany Anybody Porta Westfalica
While the situation would be heavily improved by 🐛 Fields with unlimited cardinality show 1 extra input field Needs work , I think the more directly related issue is #3176429: [PP-1] Empty entity reference is being created [Simple Widget] → . Still, all three are closely related, but this one is independent enough to not postpone it on the core issue.
Even if the core issue did not exist, IEF would validate required fields and save empty entities for IEF lines that were added manually.
So this issue should focus on finding a way to let the target entity types validate the input and tell if the entity to be saved is empty. If it is empty, the validation should be skipped. So maybe this should instead be postponed on a core issue that adds empty-checks for entity form values based on the entity type knowledge!
(Which is a general (unresolved) issue, also for similar modules like Paragraphs, etc.)