I'm working on an inline references module that will load referenced node content and allow pop-up editing of that content, but I'm having trouble firing js after a new node is created and then referenced. Since I can't control order of execution for events bound to popups_form_success, it would be best for me if popups: add and reference triggered .change() after updating a reference value and I bound my functionality to the change event. Other modules reacting off of a nodereference field value changing would benefit from this as well.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cYu’s picture

Bah, I guess it isn't as easy as I was trying to make it. When .find() finds nothing and then .end().change() is fired it will throw JS errors. My jquery chops are a bit lacking, so I don't know the best way of making this happen conditionally.

cYu’s picture

Status: Needs review » Needs work
cYu’s picture

Status: Needs work » Needs review
FileSize
1.71 KB

Is something like this sensible?

starbow’s picture

Interesting.
Can't you just bind an onChange trigger to the elements directly in your custom code?

cYu’s picture

Yes, my code is bound to change() but without this patch it is not fired after a new nodereference is created in popups: add and reference. I thought it would, but doing something like

$emptyAutos.eq(0).val(title);

to change the input's value will not fire the change event, which is what this patch would explicitly do after form element values are set.

starbow’s picture

Version: 6.x-1.x-dev » 6.x-2.0-alpha1
Status: Needs review » Needs work

Ok, that totally makes sense.
If you can change the patch to be against 2.0-alpha1 (the 1.0 branch is closed to new features), and try extracting

function() {
+          if (this) {
+            this.change();
+          }

into a stand alone function, to keep the code neat, I will put it into 2.0-alpha2.

Thanks,
-t

cYu’s picture

Status: Needs work » Needs review
FileSize
1.89 KB

Ok, I've moved that code into it's own function. My testing indicated that .end() was not needed in the places I was using it so I removed those calls.

ulechka’s picture

FileSize
713 bytes

Hello!
I've changed your patch a little, just added nid to autocompletion field this way:
$emptyAutos.eq(0).val(title + ' [nid:' + nid + ']').change();

and now inline references really works for me after popups "Add new [node-type]"