Trigger Change Events after newly created nodes are referenced

cYu - March 19, 2009 - 19:50
Project:Popups: Add and Reference
Version:6.x-2.0-alpha1
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review
Description

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.

AttachmentSize
trigger_change.patch1.56 KB

#1

cYu - March 19, 2009 - 20:13

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.

#2

cYu - March 19, 2009 - 20:13
Status:needs review» needs work

#3

cYu - March 19, 2009 - 20:21
Status:needs work» needs review

Is something like this sensible?

AttachmentSize
trigger_change.patch 1.71 KB

#4

starbow - March 21, 2009 - 00:54

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

#5

cYu - March 23, 2009 - 14:50

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.

#6

starbow - March 23, 2009 - 20:11
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

#7

cYu - March 26, 2009 - 17:37
Status:needs work» needs review

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.

AttachmentSize
trigger_change.patch 1.89 KB
 
 

Drupal is a registered trademark of Dries Buytaert.