I have a content type with three nodereferences:

NodereferenceA
NodereferenceB
NodereferenceC

which are supposed to reference nodes of the three different content types A, B and C. Actually, NodereferenceC is an unlimited set, but I don't know if it is relevant.

If I enable Modal Nodereference for NodereferenceC and fill it before I fill NodereferenceA and NodereferenceB, I get that NodereferenceA and NodereferenceB are filled in with the same value as the node I create in a modal window for NodereferenceC. This leads to validation errors.

If, instead, NodereferenceA and NodereferenceB have already been filled when I open the modal windows for NodereferenceC, I don't experience the issue.

Comments

whytewolf’s picture

I am also have this issue.

mbutcher’s picture

I can replicate this too. Looking into a patch.

very_random_man’s picture

Also, if you have multiple value modal_noderefs with an empty field and a modal_nodref underneath, the second field will populate the empty multi-value field instead of itself.

I think the problem is probably down to how it identifies which form element to update with the newly created reference.

Multiple modal-noderef fields all have the same class so it will populate all empty fields. The Create link needs relating to the field in someway. I would guess that the nodereference field id needs to be added in some fashion.

Would it be semantically correct to use the rel attribute of the link for this?

robert castelo’s picture

Shouldn't it target the field ID?

That would also make it quicker.

very_random_man’s picture

Yes. My suggestion was to keep the id of the the target nodereference element in the rel of the clicked link so that the button contains the means to directly identify the appropriate target.

gleroux02’s picture

I am wondering if this may also just be an easy fix in modal_noderef.js. It looks like this problem can be solved by switching how the last form field is found from prevAll() to prev(). I will test and try to get a patch up.

gleroux02’s picture

Here is that patch. It is replacing prevAll() with prev().

sutharsan’s picture

Status: Active » Needs review
StatusFileSize
new2.55 KB

Here is another patch based on Robert's suggestion to use the id of the field wrapper.

jdschroeder’s picture

Status: Needs review » Needs work

For me, installing either of those patches results in an alert box error message of "All available items are full. Either delete one or try adding another item first." upon clicking on any "create new" link.

jdschroeder’s picture

For what it's worth, my current workaround is replacing the aforementioned prevAll('div') with prevAll('div:first'). That seems to be doing the trick, for now.

sutharsan’s picture

@jdschroeder: can you describe your situation so others can reproduce your situation where the other patches did not apply?

jdschroeder’s picture

Sure.

I have several different node reference fields, each referencing a different content type, and all have the option to use modal_noderef enabled. As described in the original issue, if I use the modal window to create a new referenced node, any item above that was left blank is populated with the same node reference data as the targeted field.

I have separately tried each of the patches from comments 7 and 8. In both instances, when I click on the link below the field that should summon the modal dialog box, I instead receive a javascript alert box with the error message "All available items are full. Either delete one or try adding another item first."

The wildcards here may be that I am using the 1.6 release of Modal Frame API and not using jQuery Update. I will give it another try with modalframe 1.7 and updates to jQuery and jQuery UI.

paulmckibben’s picture

Status: Needs work » Needs review
StatusFileSize
new785 bytes

Well, here's my attempt at fixing it, and my rationale for this approach as opposed to the others offered here so far.

The approach:

1. This patch still uses prevAll().

2. Instead of passing the full result of prevAll() to firstEmpty(), this patch iterates one-by-one through the prevAll() results and STOPS once firstEmpty returns a valid field. This prevents the other fields from being filled.

Why not use prev() instead of prevAll()? Because I want to be safe--though I have not run into a scenario where prev() wouldn't work, I'm assuming that the original author had a good reason.

Why not use the rel attribute? Because that appears to be a non-standard use of the rel attribute, based on my reading of the XHTML standard. Take that for what it's worth. :)

mbutcher’s picture

Anyone tested this patch? Is it working solidly?

internetter’s picture

Patch in #13 works for me. Without it has filled other Noderefs, with it does not!
Greate work! Thanks.

momper’s picture

the same for me:

Patch in #13 works for me. Without it has filled other Noderefs, with it does not!
Greate work! Thanks.

mbutcher’s picture

Status: Needs review » Fixed

The patch in #13 has been pushed into CVS.

Status: Fixed » Closed (fixed)

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