I have a product display type that has a required product reference field, which can accept multiple values. When using the Inline entity form - Multiple values widget for this field, it is possible to save without adding any products.

Members fund testing for the Drupal project. Drupal Association Learn more


bojanz’s picture

EDIT: Confirmed.

nigelw’s picture

Yep. Can confirm this too.

Steps to reproduce.

  1. Use Commerce Kickstart
  2. Change any product (node) display's product reference field (a.k.a Product variations field) and set it to "Allow users to add existing variations."
  3. By default these fields are already set to required
  4. Add a product with only a title and hit submit.

Node is saved and you were't forced to either select an existing product entity or to create a new one.

timwood’s picture

I can confirm this as well, not using Commerce.

Cellar Door’s picture

Status: Active » Needs review
651 bytes

Alright I've put together a patch that hopefully will work. I put it in the inline_entity_form_save_row_weights since that seems to be the #element_validate for the multiple add widget. Works on my setup but I'm using it with Nodes so it'll need some testing.

If there's a better way to do it let me know and I can re-roll

vasike’s picture

Status: Needs review » Reviewed & tested by the community
648 bytes

i also confirm the issue.
the patch from #4 seems to provide the solution.
there's a little "trailing whitespace" in the patch.
here is a new patch whithouth the "trailing whitespace".

Cellar Door’s picture

Actually I just found a bug in my code - It trips an error when the IEF is filled out but not "saved". I'll re-write the patch with this in mind and push up later today/tomorrow.

Thanks for catching the trailing whitespace vasike!

bojanz’s picture

Status: Reviewed & tested by the community » Needs work

Waiting for a new patch then :)

Cellar Door’s picture

Bojanz -

I've looked into it more and it seems that this issue may be 2 part. The patch I submitted up above looks for a saved IEF form on required fields. This works as designed but the following situation needs further exploring:

Usually when an IEF is filled out but not "submitted" the main submit for the node form submits all the IEF forms and processes as normal. However when this happens, the form_error does not stop this process. What happens is the error is triggered but the entire form is submitted in the background and then the error showed.

So there are 2 options here:

1. If multiple IEF not saved the form does not save
2. Iterate through form for required fields and set error if values not given.

What do you think?

dww’s picture

Sounds a bit like this might be related to the bugs with nested IEF. In my case, I'm seeing duplicate entities getting created on a grandparent form when the parent form uses IEF to try to create a child. ;) Perhaps it's related to this background form submit magic. I still haven't had a chance to dig into the code, but just wanted to raise it as another possible data point...


vasike’s picture

Status: Needs work » Needs review
2.24 KB

here is a new patch that should solve the issue mention at #6 - filled IEF.
built on separate validation function.

also add the the required marker to IEF label.

Dave Reid’s picture

Priority: Normal » Major

Updating to major based on https://drupal.org/node/45111

tannerjfco’s picture

Status: Needs review » Needs work

Patch applied against 7.x-1.3 & tested. Works if widget is configured as single value, but does not work if widget is configured as multiple values and no action is chosen on the multiple value widget - that is, if the form is submitted without either selecting "add new" or "add existing", the form will still submit without a reference being made. If "add new" or "add existing" are selected, and the required values aren't filled, the form will fail validation as expected.

vasike’s picture

Status: Needs work » Needs review
1.97 KB

@Tannerjf : indeed. Thank you Sir.
here is patch that corrects that and also removes some trailing whitespaces from previous one.

tannerjfco’s picture

Status: Needs review » Reviewed & tested by the community

Sorry for the delay, but I finally got this tested again, and the issues I noted in #12 look to be fully resolved. I think we're ready to roll here :)

nicoz’s picture

Can confirm patch works as well. Thanks @vasike.

@bojanz, do you have some time for a small commit/release, seeing as how this is pretty major?

JulienD’s picture

The patch is solving the issue, multiples inline entity form are now marked as required.

bendiy’s picture

Status: Reviewed & tested by the community » Needs work

#13 works fine from a main form, but stops working if the form is embedded in another form.

For example, add an IEF multiple field to Commerce's Customer Billing profile and make it required. If you're editing an order directly, the required IEF is enforced:

However, if you go through the checkout process that uses panes to embed the profile and handle the submit, the required IEF is not enforced:

It appears to be caused by using the 'triggering_element' to enforce the requirement:

  // Only react on the submission of the parent form.
  if (empty($form_state['triggering_element']['#ief_submit_all'])) {
bendiy’s picture

Status: Needs work » Needs review
1.96 KB

The attached patch checks for:

  // Only react on the submission of the parent form.
  if (count($form_state['triggering_element']['#parents']) > 1) {

I'm not sure if this is the best way to find the parent submit button, but I'm assuming if there is more than 1 parent, this is a child submit and not the final parent submit button. This fixes this issue I raised in #17.

Is there a better way to tell when the parent submit button on a form is being clicked?

bojanz’s picture

Issue summary: View changes
Status: Needs review » Fixed

Reworked the patch and committed it:

The validation runs only if the add new / add existing form is closed, since the submission of that form does the job for us (either by preventing submission of the parent form, or by adding a new referenced entity).
Added a code comment to explain this.
Also made the required message match other drupal required messages.

I've reverted bendiy's fix for nested forms because it's not the job of this issue to fix nested IEF's.

Let me know if you encounter any issues.

Status: Fixed » Closed (fixed)

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